Keep webpackIgnore comments when building js package (#3132)

It adds terser config to not strip `/* webpackIgnore */` comments instead of
using sed after build.
This commit is contained in:
Gyeongjae Choi 2022-09-20 01:28:54 +09:00 committed by Hood Chatham
parent bb9268f01f
commit fcf7b9c5e8
3 changed files with 6 additions and 7 deletions

View File

@ -77,10 +77,6 @@ node_modules/.installed : src/js/package.json src/js/package-lock.json
dist/pyodide.js src/js/_pyodide.out.js: src/js/*.ts src/js/pyproxy.gen.ts src/js/error_handling.gen.ts node_modules/.installed
npx rollup -c src/js/rollup.config.js
# Add /* webpackIgnore: true */ to each dynamic import in `pyodide.js`.
# Rollup strips comments so this can't be done via the source file.
# We use ! as the sed separator because the replacement text includes /
sed -i 's!await import(!await import(/* webpackIgnore: true */ !g' dist/pyodide.js
dist/package.json : src/js/package.json
cp $< $@

View File

@ -178,7 +178,7 @@ export let loadScript: (url: string) => Promise<void>;
if (globalThis.document) {
// browser
loadScript = async (url) => await import(url);
loadScript = async (url) => await import(/* webpackIgnore: true */ url);
} else if (globalThis.importScripts) {
// webworker
loadScript = async (url) => {
@ -188,7 +188,7 @@ if (globalThis.document) {
} catch (e) {
// importScripts throws TypeError in a module type web worker, use import instead
if (e instanceof TypeError) {
await import(url);
await import(/* webpackIgnore: true */ url);
} else {
throw e;
}
@ -216,6 +216,6 @@ async function nodeLoadScript(url: string) {
} else {
// Otherwise, hopefully it is a relative path we can load from the file
// system.
await import(nodeUrlMod.pathToFileURL(url).href);
await import(/* webpackIgnore: true */ nodeUrlMod.pathToFileURL(url).href);
}
}

View File

@ -35,6 +35,9 @@ function config({ input, output, name, format, minify }) {
? terser({
compress: true,
mangle: false,
format: {
comments: /^\s*webpackIgnore/,
},
})
: undefined,
].filter(Boolean),