Skip to content

Commit cb66278

Browse files
committed
[CONFIG] Added support for preserveFileNames option
Fixes #41
1 parent 0de53d0 commit cb66278

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const defaultConfig = {
1010
sourcemap: 'false',
1111
loadPath: '',
1212
preserveSource: false,
13+
preserveFileNames: false,
1314
enableUnicode: false,
1415
pattern: /web-worker:(.+)/,
1516
inline: true,
@@ -31,6 +32,7 @@ module.exports = function workerLoaderPlugin(userConfig = null) {
3132
const state = {
3233
idMap: new Map(),
3334
exclude: new Set(),
35+
outFiles: new Map(),
3436
options: null,
3537
basePath: null,
3638
forceInlineCounter: 0,

src/plugin/resolveId.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,23 @@ function resolveId(state, config, importee, importer) {
4444
input: target,
4545
});
4646

47+
let workerName;
48+
if (config.preserveFileNames) {
49+
const extension = path.extname(target);
50+
workerName = path.basename(target, extension);
51+
if (!state.outFiles.has(workerName)) {
52+
state.outFiles.set(workerName, 0);
53+
} else {
54+
const duplicateCount = state.outFiles.get(workerName);
55+
state.outFiles.set(workerName, duplicateCount + 1);
56+
workerName += duplicateCount + 1;
57+
}
58+
} else {
59+
workerName = `web-worker-${state.idMap.size}`;
60+
}
61+
4762
state.idMap.set(prefixed, {
48-
workerID: `web-worker-${state.idMap.size}.js`,
63+
workerID: `${workerName}.js`,
4964
chunk: null,
5065
inputOptions,
5166
target,

0 commit comments

Comments
 (0)