Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: tweak build config #18622

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get slightly smaller bundle.

}),
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,
Copy link
Member Author

@sapphi-red sapphi-red Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sourcemap is not set in sharedNodeOptions.output, but removed because the default value is 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

Comment on lines +301 to +302
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only inject __require if needed.

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'),
Comment on lines -21 to -22
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has changed by #18460

...Object.keys(pkg.peerDependencies),
...Object.keys(pkg.devDependencies),
]

export default defineConfig({
Expand Down