diff --git a/packages/vite/rollup.config.ts b/packages/vite/rollup.config.ts index 9ad04d55a3658a..6759ede01d14c2 100644 --- a/packages/vite/rollup.config.ts +++ b/packages/vite/rollup.config.ts @@ -86,7 +86,11 @@ const sharedNodeOptions = defineConfig({ } }) -function createNodePlugins(isProduction: boolean, sourceMap = true): Plugin[] { +function createNodePlugins( + isProduction: boolean, + sourceMap: boolean, + declarationDir: string | false +): Plugin[] { return [ alias({ // packages with "module" field that doesn't play well with cjs bundles @@ -105,17 +109,8 @@ function createNodePlugins(isProduction: boolean, sourceMap = true): Plugin[] { exclude: ['src/**/__tests__/**'], esModuleInterop: true, sourceMap, - // in production we use api-extractor for dts generation - // in development we need to rely on the rollup ts plugin - ...(isProduction - ? { - declaration: false, - sourceMap: false - } - : { - declaration: true, - declarationDir: path.resolve(__dirname, 'dist/node') - }) + declaration: declarationDir !== false, + declarationDir: declarationDir !== false ? declarationDir : undefined }), // Some deps have try...catch require of optional deps, but rollup will @@ -186,7 +181,13 @@ function createNodeConfig(isProduction: boolean) { ...Object.keys(pkg.dependencies), ...(isProduction ? [] : Object.keys(pkg.devDependencies)) ], - plugins: createNodePlugins(isProduction) + plugins: createNodePlugins( + isProduction, + false, + // in production we use api-extractor for dts generation + // in development we need to rely on the rollup ts plugin + isProduction ? false : path.resolve(__dirname, 'dist/node') + ) }) } @@ -232,7 +233,7 @@ function createCjsConfig(isProduction: boolean) { ...Object.keys(pkg.dependencies), ...(isProduction ? [] : Object.keys(pkg.devDependencies)) ], - plugins: [...createNodePlugins(false, false), bundleSizeLimit(55)] + plugins: [...createNodePlugins(false, false, false), bundleSizeLimit(55)] }) }