Resolves [14 Dependabot Alerts](https://github.com/twentyhq/twenty/security/dependabot?q=is%3Aopen+package%3Avite+manifest%3Ayarn.lock+has%3Apatch) simultaneously. Vitest 1.4.0 was imported in root package.json, which further imported Vite 5. However, Vitest solved no purpose at the moment since we still rely on Jest for testing. Therefore, removed the package and we can import the latest 4x version when we move from Jest to Vitest. For the rest of the use-cases of Vite, ran `yarn up vite --recursive` for the version used to be greater than 7.0.8. <p align="center"> <img width="403" height="132" alt="image" src="https://github.com/user-attachments/assets/a4ff7a75-2e3f-4dea-9f40-9cfdf07d6252" /> </p>
146 lines
4.0 KiB
TypeScript
146 lines
4.0 KiB
TypeScript
import react from '@vitejs/plugin-react-swc';
|
|
import wyw from '@wyw-in-js/vite';
|
|
import * as path from 'path';
|
|
import { defineConfig } from 'vite';
|
|
import checker from 'vite-plugin-checker';
|
|
import dts, { type PluginOptions } from 'vite-plugin-dts';
|
|
import svgr from 'vite-plugin-svgr';
|
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
|
|
type Checkers = Parameters<typeof checker>[0];
|
|
|
|
import packageJson from './package.json';
|
|
|
|
const entries = Object.keys(packageJson.exports)
|
|
.filter((el) => el !== './style.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.dev.json');
|
|
|
|
const checkersConfig: Checkers = {
|
|
typescript: {
|
|
tsconfigPath: tsConfigPath,
|
|
},
|
|
};
|
|
|
|
const dtsConfig: PluginOptions = {
|
|
entryRoot: 'src',
|
|
tsconfigPath: tsConfigPath,
|
|
};
|
|
|
|
return {
|
|
css: {
|
|
modules: {
|
|
localsConvention: 'camelCaseOnly',
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
exclude: ['../../node_modules/.vite', '../../node_modules/.cache'],
|
|
},
|
|
root: __dirname,
|
|
cacheDir: '../../node_modules/.vite/packages/twenty-ui',
|
|
assetsInclude: ['src/**/*.svg'],
|
|
plugins: [
|
|
react({
|
|
jsxImportSource: '@emotion/react',
|
|
plugins: [['@swc/plugin-emotion', {}]],
|
|
}),
|
|
tsconfigPaths({
|
|
projects: ['tsconfig.json'],
|
|
}),
|
|
svgr(),
|
|
dts(dtsConfig),
|
|
checker(checkersConfig),
|
|
wyw({
|
|
include: [
|
|
'**/OverflowingTextWithTooltip.tsx',
|
|
'**/Tag.tsx',
|
|
'**/Avatar.tsx',
|
|
'**/Chip.tsx',
|
|
'**/LinkChip.tsx',
|
|
'**/Avatar.tsx',
|
|
'**/AvatarChipLeftComponent.tsx',
|
|
'**/ContactLink.tsx',
|
|
'**/RoundedLink.tsx',
|
|
],
|
|
babelOptions: {
|
|
presets: ['@babel/preset-typescript', '@babel/preset-react'],
|
|
},
|
|
}),
|
|
],
|
|
// Configuration for building your library.
|
|
// See: https://vitejs.dev/guide/build.html#library-mode
|
|
build: {
|
|
cssCodeSplit: false,
|
|
minify: 'esbuild',
|
|
sourcemap: 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 packages that should not be bundled into your library.
|
|
external: Object.keys(packageJson.dependencies || {}),
|
|
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',
|
|
},
|
|
interop: 'auto',
|
|
esModule: true,
|
|
exports: 'named',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'),
|
|
},
|
|
],
|
|
},
|
|
},
|
|
logLevel: 'error',
|
|
};
|
|
});
|