mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-13 08:44:02 +02:00
Use a babel plugin in order to strip /src/ from the import paths
This commit is contained in:
parent
5279646985
commit
2eb145f3f1
@ -292,6 +292,20 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
|
||||
};
|
||||
}
|
||||
|
||||
function babelPluginStripSrcPath() {
|
||||
return {
|
||||
name: "babel-plugin-strip-src-path",
|
||||
visitor: {
|
||||
"ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration":
|
||||
function ({ node }) {
|
||||
if (node.source?.value.includes("/src/")) {
|
||||
node.source.value = node.source.value.replace("/src/", "/");
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function preprocessPDFJSCode(ctx, content) {
|
||||
return transformSync(content, {
|
||||
configFile: false,
|
||||
@ -299,4 +313,8 @@ function preprocessPDFJSCode(ctx, content) {
|
||||
}).code;
|
||||
}
|
||||
|
||||
export { babelPluginPDFJSPreprocessor, preprocessPDFJSCode };
|
||||
export {
|
||||
babelPluginPDFJSPreprocessor,
|
||||
babelPluginStripSrcPath,
|
||||
preprocessPDFJSCode,
|
||||
};
|
||||
|
||||
10
gulpfile.mjs
10
gulpfile.mjs
@ -15,6 +15,7 @@
|
||||
|
||||
import {
|
||||
babelPluginPDFJSPreprocessor,
|
||||
babelPluginStripSrcPath,
|
||||
preprocessPDFJSCode,
|
||||
} from "./external/builder/babel-plugin-pdfjs-preprocessor.mjs";
|
||||
import { exec, execSync, spawn, spawnSync } from "child_process";
|
||||
@ -1592,6 +1593,7 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
||||
],
|
||||
plugins: [
|
||||
[babelPluginPDFJSPreprocessor, ctx],
|
||||
[babelPluginStripSrcPath],
|
||||
[
|
||||
"add-header-comment",
|
||||
{
|
||||
@ -1604,13 +1606,7 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
||||
sourceFileName: relativeSourcePath,
|
||||
});
|
||||
|
||||
let code = result.code;
|
||||
code = code.replaceAll(
|
||||
/(\sfrom\s".*?)(?:\/src)(\/[^"]*"?;)$/gm,
|
||||
(all, prefix, suffix) => prefix + suffix
|
||||
);
|
||||
|
||||
file.contents = Buffer.from(code);
|
||||
file.contents = Buffer.from(result.code);
|
||||
// Attach the source map to the file for gulp-sourcemaps
|
||||
if (result.map) {
|
||||
file.sourceMap = result.map;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user