Files
twenty/packages/twenty-emails/vite.config.ts
T
Parship Chowdhury 6ee5413951 chore(vite): replace vite-tsconfig-paths with resolve.tsconfigPaths (#22100)
### Summary
Migrates main monorepo packages from the `vite-tsconfig-paths` plugin to
vite’s built-in path resolution.

Vite 8 showing this warning when the plugin is detected:
> The plugin "vite-tsconfig-paths" is detected. Vite now supports
tsconfig paths resolution natively via the resolve.tsconfigPaths option.
You can remove the plugin and set resolve.tsconfigPaths: true in your
Vite config instead.

### References
- https://vite.dev/config/shared-options#resolve-tsconfigpaths
- https://vite.dev/guide/features#paths
- https://github.com/vitejs/vite/pull/21781

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/22100?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>
2026-06-24 19:03:18 +02:00

92 lines
2.5 KiB
TypeScript

import { builtinModules } from 'node:module';
import { lingui } from '@lingui/vite-plugin';
import react from '@vitejs/plugin-react-swc';
import * as path from 'path';
import { APP_LOCALES } from 'twenty-shared/translations';
import { defineConfig, type Plugin } from 'vite';
// twenty-emails bundles its deps (the Node server that consumes it doesn't have
// @react-email et al.) but runs in Node. A plain client/lib build under Vite 8
// (rolldown) resolves node builtins to browser stubs that throw at runtime
// (e.g. object-inspect reading util.inspect.custom), crashing the server on
// import. Vite only externalizes builtins as real `require('node:*')` in an
// SSR/node build, so this is built with `build.ssr` + `ssr.target: 'node'`,
// while `ssr.noExternal: true` keeps the npm deps bundled in. React stays
// external as the host app provides it.
const EXTERNAL_DEPENDENCIES = ['react', 'react-dom', 'react/jsx-runtime'];
const nodeBuiltins = new Set([
...builtinModules,
...builtinModules.map((moduleName) => `node:${moduleName}`),
]);
const externalizeNodeBuiltins = (): Plugin => ({
name: 'externalize-node-builtins',
enforce: 'pre',
resolveId(source) {
const specifier = source.startsWith('node:') ? source : `node:${source}`;
if (nodeBuiltins.has(source) || nodeBuiltins.has(specifier)) {
return { id: specifier, external: true };
}
return null;
},
});
export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/packages/twenty-emails',
resolve: {
tsconfigPaths: true,
alias: {
'@/': path.resolve(__dirname, 'src') + '/',
'src/': path.resolve(__dirname, 'src') + '/',
},
},
ssr: {
target: 'node',
noExternal: true,
external: EXTERNAL_DEPENDENCIES,
},
plugins: [
externalizeNodeBuiltins(),
react({
plugins: [['@lingui/swc-plugin', {}]],
}),
lingui({
configPath: path.resolve(__dirname, './lingui.config.ts'),
}),
],
build: {
outDir: './dist',
ssr: true,
reportCompressedSize: false,
commonjsOptions: {
transformMixedEsModules: true,
},
lib: {
entry: {
index: 'src/index.ts',
...Object.values(APP_LOCALES).reduce(
(acc, locale) => ({
...acc,
[`locales/generated/${locale}`]: `src/locales/generated/${locale}.ts`,
}),
{},
),
},
name: 'twenty-emails',
formats: ['es', 'cjs'],
},
rollupOptions: {
external: EXTERNAL_DEPENDENCIES,
},
},
});