216a7331f8
## Summary - Removed `vite-plugin-dts` (which used `tsc` internally) from the Vite build and replaced DTS generation with `tsgo` as a sequential post-build step — **~0.7s vs 1-10s**. - Disabled `reportCompressedSize` to skip gzip computation for 64 output files. - Converted the build target to an explicit `nx:run-commands` executor with sequential `vite build` → `tsgo` commands. The `twenty-emails:build` step goes from ~22s to ~7s under load. ## Test plan - [x] `nx build twenty-emails` produces both JS (64 files) and DTS (74 files) correctly - [x] `dist/index.d.ts` exports match the source `src/index.ts` - [x] Full `nx build twenty-server` succeeds end-to-end - [ ] CI build passes Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor <cursoragent@cursor.com>
135 lines
3.4 KiB
TypeScript
135 lines
3.4 KiB
TypeScript
import path from 'path';
|
|
import { defineConfig } from 'vite';
|
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
import packageJson from './package.json';
|
|
import { type PackageJson } from 'type-fest';
|
|
|
|
const entries = [
|
|
'src/index.ts',
|
|
'src/cli/cli.ts',
|
|
'src/ui/index.ts',
|
|
'src/front-component/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}`,
|
|
);
|
|
}
|
|
|
|
// Find which entry this chunk corresponds to
|
|
const entry = entries.find((e) => chunk.facadeModuleId?.endsWith(e));
|
|
if (!entry || entry === 'src/index.ts' || entry === 'src/cli/cli.ts') {
|
|
return `${chunk.name}.${extension}`;
|
|
}
|
|
|
|
// Remove 'src/' prefix and '/index.ts' suffix to get the module path
|
|
const modulePath = entry.replace('src/', '').replace('/index.ts', '');
|
|
return `${modulePath}/index.${extension}`;
|
|
};
|
|
|
|
export default defineConfig(() => {
|
|
return {
|
|
root: __dirname,
|
|
cacheDir: '../../node_modules/.vite/packages/twenty-sdk',
|
|
resolve: {
|
|
alias: {
|
|
'@/': path.resolve(__dirname, 'src') + '/',
|
|
},
|
|
},
|
|
plugins: [
|
|
tsconfigPaths({
|
|
root: __dirname,
|
|
}),
|
|
],
|
|
worker: {
|
|
format: 'iife',
|
|
rollupOptions: {
|
|
output: {
|
|
inlineDynamicImports: true,
|
|
},
|
|
},
|
|
plugins: () => [
|
|
{
|
|
name: 'define-process-env',
|
|
transform: (code: string) =>
|
|
code
|
|
.replace(/process\.env\.NODE_ENV/g, JSON.stringify('production'))
|
|
.replace(/process\.env/g, '{}'),
|
|
},
|
|
],
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
lib: { entry: entries, name: 'twenty-sdk' },
|
|
rollupOptions: {
|
|
onwarn: (warning, warn) => {
|
|
// Suppress "use client" directive warnings from framer-motion
|
|
if (
|
|
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
|
|
warning.message.includes('"use client"')
|
|
) {
|
|
return;
|
|
}
|
|
warn(warning);
|
|
},
|
|
external: (id: string) => {
|
|
if (/^node:/.test(id)) {
|
|
return true;
|
|
}
|
|
|
|
const builtins = [
|
|
'path',
|
|
'fs',
|
|
'fs/promises',
|
|
'url',
|
|
'crypto',
|
|
'stream',
|
|
'util',
|
|
'os',
|
|
'module',
|
|
];
|
|
|
|
if (builtins.includes(id)) {
|
|
return true;
|
|
}
|
|
|
|
const deps = Object.entries(
|
|
(packageJson as PackageJson).dependencies || {},
|
|
).filter(([_, version]) => !version?.startsWith('workspace:'));
|
|
|
|
return deps.some(
|
|
([dep, _]) => id === dep || id.startsWith(dep + '/'),
|
|
);
|
|
},
|
|
output: [
|
|
{
|
|
format: 'es',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'),
|
|
},
|
|
{
|
|
format: 'cjs',
|
|
interop: 'auto',
|
|
esModule: true,
|
|
exports: 'named',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'),
|
|
},
|
|
],
|
|
},
|
|
},
|
|
logLevel: 'warn',
|
|
optimizeDeps: {
|
|
include: [
|
|
'@remote-dom/core/polyfill',
|
|
'@remote-dom/react/polyfill',
|
|
'@remote-dom/core/elements',
|
|
'@remote-dom/react',
|
|
'@remote-dom/react/host',
|
|
'react-dom/client',
|
|
'react/jsx-runtime',
|
|
],
|
|
},
|
|
};
|
|
});
|