1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-11 19:58:15 +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:
Jonas Jenwald 2025-04-04 12:30:15 +02:00 committed by GitHub
commit 0bde69c7bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View file

@ -173,6 +173,36 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
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": {
// Visit node in post-order so that recursive flattening
// of blocks works correctly.

View file

@ -0,0 +1,4 @@
const wasmUrl = new URL(
/*webpackIgnore: true*/
/*@vite-ignore*/
"qwerty.wasm", import.meta.url);

View file

@ -0,0 +1 @@
const wasmUrl = new URL("qwerty.wasm" , import.meta.url);