Reduce size of standalone.js (#13543)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-10-04 18:09:24 +08:00
1 parent 933834984e
commit 572452acf8
2 files changed
+37 -3

No files matched your search

+28
View File
@@ -61,6 +61,25 @@ function getEsbuildOptions({ file, files, shouldCollectLicenses, cliOptions }) {
return text.slice(0, index);
},
},
/*
`jest-docblock` try to detect new line in code, and it will fallback to `os.EOL`,
We already replaced line end to `\n` before calling it
*/
{
module: require.resolve("jest-docblock"),
process: (text) =>
text
.replace(
"const line = (0, _detectNewline().default)(docblock) || _os().EOL;",
'const line = "\\n"'
)
.replace(
"const line = (0, _detectNewline().default)(comments) || _os().EOL;",
'const line = "\\n"'
)
.replace(/\nfunction _os().*?\n}/s, "")
.replace(/\nfunction _detectNewline().*?\n}/s, ""),
},
];
const define = {
@@ -120,6 +139,15 @@ function getEsbuildOptions({ file, files, shouldCollectLicenses, cliOptions }) {
find: 'import { createRequire } from "node:module";',
replacement: "",
},
// Prevent `esbuildPluginNodeModulePolyfills` shim `assert`, which will include a big `buffer` shim
// TODO[@fisker]: Find a better way
{
module: "*",
find: ' from "node:assert";',
replacement: ` from ${JSON.stringify(
path.join(dirname, "./shims/assert.js")
)};`,
},
// Prevent `esbuildPluginNodeModulePolyfills` include shim for this module
{
module: "assert",