Skip to content

Commit

Permalink
chore: tweak build config (#18622)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 8, 2024
1 parent 0924879 commit 2a88f71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
19 changes: 7 additions & 12 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function createSharedNodePlugins({
// Since ws is not that perf critical for us, just ignore these deps.
ignore: ['bufferutil', 'utf-8-validate'],
sourceMap: false,
strictRequires: 'auto',
}),
json(),
]
Expand All @@ -108,13 +109,10 @@ const nodeConfig = defineConfig({
},
external: [
/^vite\//,
'lightningcss',
'rollup/parseAst',
// postcss-load-config
'yaml',
'jiti',
/^tsx(\/|$)/,
/^tsx\//,
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies),
],
plugins: [
// Some deps have try...catch require of optional deps, but rollup will
Expand Down Expand Up @@ -197,14 +195,10 @@ const cjsConfig = defineConfig({
publicUtils: path.resolve(__dirname, 'src/node/publicUtils.ts'),
},
output: {
dir: './dist',
...sharedNodeOptions.output,
entryFileNames: `node-cjs/[name].cjs`,
chunkFileNames: 'node-cjs/chunks/dep-[hash].js',
exports: 'named',
format: 'cjs',
externalLiveBindings: false,
freeze: false,
sourcemap: false,
},
external: Object.keys(pkg.dependencies),
plugins: [...createSharedNodePlugins({}), bundleSizeLimit(175)],
Expand Down Expand Up @@ -297,14 +291,15 @@ function cjsPatchPlugin(): Plugin {
const cjsPatch = `
import { createRequire as __cjs_createRequire } from 'node:module';
const require = __cjs_createRequire(import.meta.url);
const __require = require;
const __require = __cjs_createRequire(import.meta.url);
`.trimStart()

return {
name: 'cjs-chunk-patch',
renderChunk(code, chunk) {
if (!chunk.fileName.includes('chunks/dep-')) return
if (!code.includes('__require')) return

const match = /^(?:import[\s\S]*?;\s*)+/.exec(code)
const index = match ? match.index! + match[0].length : 0
const s = new MagicString(code)
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/rollup.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const external = [
/^vite\//,
'rollup/parseAst',
...Object.keys(pkg.dependencies),
// lightningcss types are bundled
...Object.keys(pkg.devDependencies).filter((d) => d !== 'lightningcss'),
...Object.keys(pkg.peerDependencies),
...Object.keys(pkg.devDependencies),
]

export default defineConfig({
Expand Down

0 comments on commit 2a88f71

Please sign in to comment.