Skip to content

Commit 8182b54

Browse files
committed
2.2.12
1 parent f59b907 commit 8182b54

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

changelog.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## V2.2.12
2-
- only use cache in watch mode
3-
- refine inject logic
4-
- add example of custom inject to tests
2+
- **[v2]** only use cache in watch mode
3+
- **[v2]** refine inject logic
4+
- **[v2]** add example of custom inject to tests
55

66
## V2.2.11
77
- replace `process.memoryUsage.rss()` to `process.memoryUsage().rss` to support Nodejs<15.6.0

lib/plugin.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22
const { createHash } = require('crypto');
3-
const { readFile, writeFile, unlink } = require('fs/promises');
3+
const { readFile, writeFile, unlink, appendFile } = require('fs/promises');
44
const {
55
getLogger,
66
buildInjectCode,
@@ -315,15 +315,16 @@ const onEnd = async (build, options, result) => {
315315
};
316316

317317
const buildJs = async (entryName, entryPath, jsCode) => {
318-
const r = (p) => `./${path.relative(absOutdir, p).split(path.sep).join(path.posix.sep)}`;
319-
const imports = `import "${r(entryPath)}";`;
320-
if ((sourceRoot || publicPath) && sourcemap) {
321-
const sp = sourceRoot || publicPath;
322-
const fixedSourceRoot = sp.endsWith('/') ? sp : sp + '/';
318+
const r = (p) => path.relative(absOutdir, p).split(path.sep).join(path.posix.sep);
319+
const imports = `import "./${r(entryPath)}";`;
320+
if (sourcemap === 'external') {
321+
await appendFile(entryPath, `\n//# sourceMappingURL=${r(entryPath)}.map`, { encoding: 'utf8' });
322+
} else if (publicPath && sourcemap) {
323+
const fixedPublicPath = publicPath.endsWith('/') ? publicPath : publicPath + '/';
323324
const entryContent = await readFile(entryPath, { encoding: 'utf8' });
324325
await writeFile(
325326
entryPath,
326-
entryContent.replace(`sourceMappingURL=${fixedSourceRoot}`, 'sourceMappingURL='),
327+
entryContent.replace(`sourceMappingURL=${fixedPublicPath}`, 'sourceMappingURL='),
327328
{ encoding: 'utf8' }
328329
);
329330
}

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fse.emptyDirSync('./dist');
106106
target: ['esnext'],
107107
bundle: true,
108108
minify: false,
109-
sourcemap: true,
109+
sourcemap: 'external',
110110
publicPath: 'https://my.domain/static/',
111111
external: ['react', 'react-dom'],
112112
outdir: './dist/bundle-v2-custom-inject',

0 commit comments

Comments
 (0)