-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
chore: tweak build config #18622
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(), | ||
] | ||
|
@@ -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 | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
external: Object.keys(pkg.dependencies), | ||
plugins: [...createSharedNodePlugins({}), bundleSizeLimit(175)], | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only inject |
||
const match = /^(?:import[\s\S]*?;\s*)+/.exec(code) | ||
const index = match ? match.index! + match[0].length : 0 | ||
const s = new MagicString(code) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
|
There was a problem hiding this comment.
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.