mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
[api-minor] Attempt to improve support for using the PDF.js builds with Vite
Similar to Webpack there's apparently other bundlers that will not leave `import`-calls alone unless magic comments are used. Hence we extend the builder to also append `/* @vite-ignore */` comments to `import`-calls, in order to attempt to improve support for using the PDF.js builds together with Vite. This patch also renames `__non_webpack_import__` to `__raw_import__` since the functionality is no longer bundler-specific. ***PLEASE NOTE:*** This patch is provided as-is, and it does *not* mean that the PDF.js project can/will provide official support for Vite.
This commit is contained in:
parent
34136d7775
commit
8bcc3664c9
8 changed files with 19 additions and 12 deletions
|
@ -153,18 +153,22 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
|
|||
path.replaceWith(t.inherits(t.valueToNode(result), path.node));
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node.callee, { name: "__non_webpack_import__" })) {
|
||||
if (t.isIdentifier(node.callee, { name: "__raw_import__" })) {
|
||||
if (node.arguments.length !== 1) {
|
||||
throw new Error("Invalid `__non_webpack_import__` usage.");
|
||||
throw new Error("Invalid `__raw_import__` usage.");
|
||||
}
|
||||
// Replace it with a standard `import`-call and
|
||||
// ensure that Webpack will leave it alone.
|
||||
// Replace it with a standard `import`-call and attempt to ensure that
|
||||
// various bundlers will leave it alone; this *must* include Webpack.
|
||||
const source = node.arguments[0];
|
||||
source.leadingComments = [
|
||||
{
|
||||
type: "CommentBlock",
|
||||
value: "webpackIgnore: true",
|
||||
},
|
||||
{
|
||||
type: "CommentBlock",
|
||||
value: "@vite-ignore",
|
||||
},
|
||||
];
|
||||
path.replaceWith(t.importExpression(source));
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { Test } from "import-name";
|
||||
import { Test2 } from './non-alias';
|
||||
export { Test3 } from "import-name";
|
||||
await import(/*webpackIgnore: true*/"./non-alias");
|
||||
await import(
|
||||
/*webpackIgnore: true*/
|
||||
/*@vite-ignore*/
|
||||
"./non-alias");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Test } from 'import-alias';
|
||||
import { Test2 } from './non-alias';
|
||||
export { Test3 } from 'import-alias';
|
||||
await __non_webpack_import__("./non-alias");
|
||||
await __raw_import__("./non-alias");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue