mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-24 07:57:22 +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) {
|
function preprocessPDFJSCode(ctx, content) {
|
||||||
return transformSync(content, {
|
return transformSync(content, {
|
||||||
configFile: false,
|
configFile: false,
|
||||||
@ -299,4 +313,8 @@ function preprocessPDFJSCode(ctx, content) {
|
|||||||
}).code;
|
}).code;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { babelPluginPDFJSPreprocessor, preprocessPDFJSCode };
|
export {
|
||||||
|
babelPluginPDFJSPreprocessor,
|
||||||
|
babelPluginStripSrcPath,
|
||||||
|
preprocessPDFJSCode,
|
||||||
|
};
|
||||||
|
|||||||
10
gulpfile.mjs
10
gulpfile.mjs
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
babelPluginPDFJSPreprocessor,
|
babelPluginPDFJSPreprocessor,
|
||||||
|
babelPluginStripSrcPath,
|
||||||
preprocessPDFJSCode,
|
preprocessPDFJSCode,
|
||||||
} from "./external/builder/babel-plugin-pdfjs-preprocessor.mjs";
|
} from "./external/builder/babel-plugin-pdfjs-preprocessor.mjs";
|
||||||
import { exec, execSync, spawn, spawnSync } from "child_process";
|
import { exec, execSync, spawn, spawnSync } from "child_process";
|
||||||
@ -1592,6 +1593,7 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
|||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
[babelPluginPDFJSPreprocessor, ctx],
|
[babelPluginPDFJSPreprocessor, ctx],
|
||||||
|
[babelPluginStripSrcPath],
|
||||||
[
|
[
|
||||||
"add-header-comment",
|
"add-header-comment",
|
||||||
{
|
{
|
||||||
@ -1604,13 +1606,7 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
|||||||
sourceFileName: relativeSourcePath,
|
sourceFileName: relativeSourcePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
let code = result.code;
|
file.contents = Buffer.from(result.code);
|
||||||
code = code.replaceAll(
|
|
||||||
/(\sfrom\s".*?)(?:\/src)(\/[^"]*"?;)$/gm,
|
|
||||||
(all, prefix, suffix) => prefix + suffix
|
|
||||||
);
|
|
||||||
|
|
||||||
file.contents = Buffer.from(code);
|
|
||||||
// Attach the source map to the file for gulp-sourcemaps
|
// Attach the source map to the file for gulp-sourcemaps
|
||||||
if (result.map) {
|
if (result.map) {
|
||||||
file.sourceMap = result.map;
|
file.sourceMap = result.map;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user