Skip to content

Commit c04961d

Browse files
committed
Updated source map logic to work with 2.17.0
1 parent f6a0771 commit c04961d

File tree

6 files changed

+2364
-78
lines changed

6 files changed

+2364
-78
lines changed

loader/index.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@
22

33
import JavaScriptObfuscator, {ObfuscatorOptions} from 'javascript-obfuscator';
44
import loaderUtils from 'loader-utils';
5+
import * as path from 'path';
6+
7+
type WebpackObfuscatorOptions = Omit<
8+
ObfuscatorOptions,
9+
| 'inputFileName'
10+
| 'sourceMapBaseUrl'
11+
| 'sourceMapFileName'
12+
| 'sourceMapMode'
13+
| 'sourceMapSourcesMode'
14+
>;
515

616
/**
717
* JavaScript Obfuscator loader based on `obfuscator-loader` package
818
*/
919
function Loader (sourceCode: string) {
10-
// Obfuscates commented source code
1120
// @ts-ignore
12-
const options = loaderUtils.getOptions<ObfuscatorOptions>(this) || {};
21+
const context = this;
22+
23+
const relativePathOfModule = path.relative(context.rootContext, context.resourcePath);
24+
25+
// Obfuscates commented source code
26+
const options = loaderUtils.getOptions<WebpackObfuscatorOptions>(context) || {};
1327
const obfuscationResult = JavaScriptObfuscator.obfuscate(
1428
sourceCode,
1529
{
1630
...options,
17-
ignoreRequireImports: true
31+
ignoreRequireImports: true,
32+
inputFileName: relativePathOfModule,
33+
sourceMapMode: 'separate'
1834
}
1935
);
2036

0 commit comments

Comments
 (0)