Skip to content

Commit 041928c

Browse files
author
sanex3339
committed
0.18.3 release: Plugin now should works
1 parent 25ff2f1 commit 041928c

File tree

4 files changed

+246
-440
lines changed

4 files changed

+246
-440
lines changed

dist/index.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,26 @@ class WebpackObfuscator {
2020
}
2121
const pluginName = this.constructor.name;
2222
compiler.hooks.emit.tap(pluginName, (compilation) => {
23-
for (const fileName in compilation.assets) {
24-
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
25-
return;
26-
}
27-
const asset = compilation.assets[fileName];
28-
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
29-
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource);
30-
if (this.options.sourceMap && inputSourceMap) {
31-
const transferredSourceMap = transferSourceMap({
32-
fromSourceMap: obfuscationSourceMap,
33-
toSourceMap: inputSource
34-
});
35-
compilation.assets[fileName] = new webpack_sources_1.SourceMapSource(obfuscatedSource, fileName, transferredSourceMap, inputSource, inputSourceMap);
36-
}
37-
else {
38-
compilation.assets[fileName] = new webpack_sources_1.RawSource(obfuscatedSource);
39-
}
40-
}
23+
compilation.chunks.forEach(chunk => {
24+
chunk.files.forEach((fileName) => {
25+
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
26+
return;
27+
}
28+
const asset = compilation.assets[fileName];
29+
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
30+
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource);
31+
if (this.options.sourceMap && inputSourceMap) {
32+
const transferredSourceMap = transferSourceMap({
33+
fromSourceMap: obfuscationSourceMap,
34+
toSourceMap: inputSource
35+
});
36+
compilation.assets[fileName] = new webpack_sources_1.SourceMapSource(obfuscatedSource, fileName, transferredSourceMap, inputSource, inputSourceMap);
37+
}
38+
else {
39+
compilation.assets[fileName] = new webpack_sources_1.RawSource(obfuscatedSource);
40+
}
41+
});
42+
});
4143
});
4244
}
4345
shouldExclude(filePath) {

index.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,36 @@ class WebpackObfuscator {
2727
'and the obfuscator can interfere with each other and break the build');
2828
return;
2929
}
30-
30+
3131
const pluginName = this.constructor.name;
3232
compiler.hooks.emit.tap(pluginName, (compilation: compilation.Compilation) => {
33-
for (const fileName in compilation.assets) {
34-
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
35-
return;
36-
}
37-
const asset = compilation.assets[fileName]
38-
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
39-
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource);
33+
compilation.chunks.forEach(chunk => {
34+
chunk.files.forEach((fileName: string) => {
35+
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
36+
return;
37+
}
38+
const asset = compilation.assets[fileName]
39+
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
40+
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource);
4041

41-
if (this.options.sourceMap && inputSourceMap) {
42-
const transferredSourceMap = transferSourceMap({
43-
fromSourceMap: obfuscationSourceMap,
44-
toSourceMap: inputSource
45-
});
42+
if (this.options.sourceMap && inputSourceMap) {
43+
const transferredSourceMap = transferSourceMap({
44+
fromSourceMap: obfuscationSourceMap,
45+
toSourceMap: inputSource
46+
});
4647

47-
compilation.assets[fileName] = new SourceMapSource(
48-
obfuscatedSource,
49-
fileName,
50-
transferredSourceMap,
51-
inputSource,
52-
inputSourceMap
53-
);
54-
} else {
55-
compilation.assets[fileName] = new RawSource(obfuscatedSource);
56-
}
57-
}
48+
compilation.assets[fileName] = new SourceMapSource(
49+
obfuscatedSource,
50+
fileName,
51+
transferredSourceMap,
52+
inputSource,
53+
inputSourceMap
54+
);
55+
} else {
56+
compilation.assets[fileName] = new RawSource(obfuscatedSource);
57+
}
58+
});
59+
});
5860
});
5961
}
6062

0 commit comments

Comments
 (0)