mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Merge pull request #19767 from Snuffleupagus/issue-19761
Attempt to get bundlers to leave Emscripten Compiler generated `URL`s alone (issue 19761)
This commit is contained in:
commit
0bde69c7bf
3 changed files with 35 additions and 0 deletions
|
@ -173,6 +173,36 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
|
||||||
path.replaceWith(t.importExpression(source));
|
path.replaceWith(t.importExpression(source));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
NewExpression(path) {
|
||||||
|
const { node } = path;
|
||||||
|
|
||||||
|
if (
|
||||||
|
t.isIdentifier(node.callee, { name: "URL" }) &&
|
||||||
|
node.arguments.length === 2
|
||||||
|
) {
|
||||||
|
const [arg1, arg2] = node.arguments;
|
||||||
|
|
||||||
|
if (
|
||||||
|
arg1.type === "StringLiteral" &&
|
||||||
|
arg1.value.endsWith(".wasm") &&
|
||||||
|
arg2.type === "MemberExpression"
|
||||||
|
) {
|
||||||
|
// This statement is generated by the Emscripten Compiler (emcc),
|
||||||
|
// however we're manually loading wasm-files and we want to ensure
|
||||||
|
// that bundlers will leave it alone; this *must* include Webpack.
|
||||||
|
arg1.leadingComments = [
|
||||||
|
{
|
||||||
|
type: "CommentBlock",
|
||||||
|
value: "webpackIgnore: true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "CommentBlock",
|
||||||
|
value: "@vite-ignore",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"BlockStatement|StaticBlock": {
|
"BlockStatement|StaticBlock": {
|
||||||
// Visit node in post-order so that recursive flattening
|
// Visit node in post-order so that recursive flattening
|
||||||
// of blocks works correctly.
|
// of blocks works correctly.
|
||||||
|
|
4
external/builder/fixtures_babel/ignore-expected.js
vendored
Normal file
4
external/builder/fixtures_babel/ignore-expected.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
const wasmUrl = new URL(
|
||||||
|
/*webpackIgnore: true*/
|
||||||
|
/*@vite-ignore*/
|
||||||
|
"qwerty.wasm", import.meta.url);
|
1
external/builder/fixtures_babel/ignore.js
vendored
Normal file
1
external/builder/fixtures_babel/ignore.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
const wasmUrl = new URL("qwerty.wasm" , import.meta.url);
|
Loading…
Add table
Add a link
Reference in a new issue