Files
twenty/packages/twenty-ui/vite.config.ts
T
Parship Chowdhury 6e319283c4 fix: Vite 8/Rolldown build warnings in library packages (#22205)
Clean up Vite 8/Rolldown build warnings that showed up during yarn
start:
- `twenty-client-sdk`: `relativeImportPath.ts` now imports `node:path`,
so the generate bundle treats it as a Node external instead of stubbing
it for the browser.
- Remove rollup’s `interop: 'auto'` from CJS output options - Rolldown
don’t support it and was showing `Invalid key: Expected never but
received "interop"`.
- Replaced deprecated `inlineDynamicImports: true` with `codeSplitting:
false` in the worker config.

References:
- https://v7.vite.dev/guide/rolldown#option-validation-warnings
-
https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/22205?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

---------

Signed-off-by: Parship Chowdhury <parshipchowdhury@gmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2026-06-29 12:59:36 +02:00

175 lines
5.0 KiB
TypeScript

import react from '@vitejs/plugin-react-swc';
import * as fs from 'fs';
import * as path from 'path';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import dts, { type PluginOptions } from 'vite-plugin-dts';
import sassDts from 'vite-plugin-sass-dts';
import svgr from 'vite-plugin-svgr';
type Checkers = Parameters<typeof checker>[0];
import packageJson from './package.json';
const entries = Object.keys(packageJson.exports)
.filter((el) => !el.endsWith('.css'))
.map((module) => `src/${module}/index.ts`);
const entryFileNames = (chunk: any, extension: 'cjs' | 'mjs') => {
if (!chunk.isEntry) {
throw new Error(
`Should never occurs, encountered a non entry chunk ${chunk.facadeModuleId}`,
);
}
const splitFaceModuleId = chunk.facadeModuleId?.split('/');
if (splitFaceModuleId === undefined) {
throw new Error(
`Should never occurs splitFaceModuleId is undefined ${chunk.facadeModuleId}`,
);
}
const moduleDirectory = splitFaceModuleId[splitFaceModuleId?.length - 2];
if (moduleDirectory === 'src') {
return `${chunk.name}.${extension}`;
}
return `${moduleDirectory}.${extension}`;
};
export default defineConfig(({ command }) => {
const isBuildCommand = command === 'build';
const tsConfigPath = isBuildCommand
? path.resolve(__dirname, './tsconfig.lib.json')
: path.resolve(__dirname, './tsconfig.json');
const checkersConfig: Checkers = {
typescript: {
tsconfigPath: tsConfigPath,
},
};
const dtsConfig: PluginOptions = {
entryRoot: 'src',
tsconfigPath: tsConfigPath,
};
const BUNDLED_DEPS: string[] = [];
const externalDeps = Object.keys({
...(packageJson.dependencies || {}),
...(packageJson.peerDependencies || {}),
}).filter((dep) => !BUNDLED_DEPS.includes(dep));
return {
resolve: {
tsconfigPaths: true,
alias: {
'@ui/': path.resolve(__dirname, 'src') + '/',
'@assets/': path.resolve(__dirname, 'src/assets') + '/',
'@styles/': path.resolve(__dirname, 'src/styles') + '/',
},
},
css: {
modules: {
localsConvention: 'camelCaseOnly',
},
preprocessorOptions: {
scss: {
api: 'modern-compiler',
loadPaths: [path.resolve(__dirname, 'src/styles')],
additionalData: [
`@use 'abstracts/functions' as *;`,
`@use 'abstracts/mixins' as *;`,
`@use 'abstracts/breakpoints' as *;`,
'',
].join('\n'),
},
},
},
optimizeDeps: {
// Pre-bundle React up front so Vite's dep optimizer doesn't re-bundle it
// mid-run during browser-mode Storybook tests — re-bundling rotates the
// optimized chunk hash and 404s in-flight dynamic imports (vite 8 / rolldown).
include: [
'react',
'react-dom',
'react-dom/client',
'react/jsx-runtime',
'react/jsx-dev-runtime',
],
},
root: __dirname,
cacheDir: 'node_modules/.vite',
assetsInclude: ['src/**/*.svg'],
plugins: [
react(),
svgr(),
// Generates typed *.module.scss.d.ts siblings (dev mode only — backed by
// sass-embedded). CI/build relies on the ambient src/scss-modules.d.ts.
sassDts({ esmExport: true, legacyFileFormat: true }),
dts(dtsConfig),
checker(checkersConfig),
{
name: 'copy-theme-css',
closeBundle() {
const distDir = path.resolve(__dirname, 'dist');
fs.mkdirSync(distDir, { recursive: true });
const themeCssFiles = ['theme-light.css', 'theme-dark.css'];
for (const file of themeCssFiles) {
fs.copyFileSync(
path.resolve(__dirname, `src/theme-constants/${file}`),
path.resolve(distDir, file),
);
}
},
},
],
build: {
cssCodeSplit: false,
minify: 'esbuild',
sourcemap: false,
emptyOutDir: false,
outDir: './dist',
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
interopDefault: true,
defaultIsModuleExports: true,
requireReturnsDefault: 'auto',
},
lib: {
entry: ['src/index.ts', ...entries],
name: 'twenty-ui',
},
rollupOptions: {
external: (id: string) =>
externalDeps.some((dep) => id === dep || id.startsWith(dep + '/')),
output: [
{
assetFileNames: 'style.css',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
format: 'es',
entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'),
},
{
assetFileNames: 'style.css',
format: 'cjs',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
esModule: true,
exports: 'named',
entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'),
},
],
},
},
logLevel: 'error',
};
});