mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Move the __non_webpack_import__
re-writing into the Babel plugin
Note how we're using custom `__non_webpack_import__`-calls in the code-base, that we replace during the post-processing stage of the build, to be able to write `import`-calls that Webpack will leave alone during parsing. This work-around is necessary since we let Babel discards all comments, given that we generally don't need/want them in the builds, hence why we cannot utilize `/* webpackIgnore: true */`-comments in the source-code. After the changes in PR 17563 it thus seems to me that we should be able to just move this re-writing into the Babel plugin instead.
This commit is contained in:
parent
d742daf4b7
commit
4ab0ad3216
4 changed files with 20 additions and 18 deletions
20
gulpfile.mjs
20
gulpfile.mjs
|
@ -419,7 +419,7 @@ function checkChromePreferencesFile(chromePrefsPath, webPrefs) {
|
|||
}
|
||||
|
||||
function tweakWebpackOutput(jsName) {
|
||||
const replacer = ["__non_webpack_import__\\("];
|
||||
const replacer = [];
|
||||
|
||||
if (jsName) {
|
||||
replacer.push(
|
||||
|
@ -431,8 +431,6 @@ function tweakWebpackOutput(jsName) {
|
|||
|
||||
return replace(regex, match => {
|
||||
switch (match) {
|
||||
case "__non_webpack_import__(":
|
||||
return "import(/* webpackIgnore: true */ ";
|
||||
case " __webpack_exports__ = {};":
|
||||
return ` __webpack_exports__ = globalThis.${jsName} = {};`;
|
||||
case " __webpack_exports__ = await __webpack_exports__;":
|
||||
|
@ -1572,17 +1570,6 @@ gulp.task("types", function (done) {
|
|||
});
|
||||
|
||||
function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
||||
function babelPluginReplaceNonWebpackImport(b) {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(curPath, state) {
|
||||
if (curPath.node.name === "__non_webpack_import__") {
|
||||
curPath.replaceWith(b.types.identifier("import"));
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
function preprocessLib(content) {
|
||||
const skipBabel = bundleDefines.SKIP_BABEL;
|
||||
content = babel.transform(content, {
|
||||
|
@ -1590,10 +1577,7 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
|||
presets: skipBabel
|
||||
? undefined
|
||||
: [["@babel/preset-env", { loose: false, modules: false }]],
|
||||
plugins: [
|
||||
babelPluginReplaceNonWebpackImport,
|
||||
[babelPluginPDFJSPreprocessor, ctx],
|
||||
],
|
||||
plugins: [[babelPluginPDFJSPreprocessor, ctx]],
|
||||
targets: BABEL_TARGETS,
|
||||
}).code;
|
||||
content = content.replaceAll(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue