Skip to content

Commit

Permalink
Updated source map logic to work with 2.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sanex3339 committed Jul 20, 2021
1 parent f6a0771 commit c04961d
Show file tree
Hide file tree
Showing 6 changed files with 2,364 additions and 78 deletions.
22 changes: 19 additions & 3 deletions loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@

import JavaScriptObfuscator, {ObfuscatorOptions} from 'javascript-obfuscator';
import loaderUtils from 'loader-utils';
import * as path from 'path';

type WebpackObfuscatorOptions = Omit<
ObfuscatorOptions,
| 'inputFileName'
| 'sourceMapBaseUrl'
| 'sourceMapFileName'
| 'sourceMapMode'
| 'sourceMapSourcesMode'
>;

/**
* JavaScript Obfuscator loader based on `obfuscator-loader` package
*/
function Loader (sourceCode: string) {
// Obfuscates commented source code
// @ts-ignore
const options = loaderUtils.getOptions<ObfuscatorOptions>(this) || {};
const context = this;

const relativePathOfModule = path.relative(context.rootContext, context.resourcePath);

// Obfuscates commented source code
const options = loaderUtils.getOptions<WebpackObfuscatorOptions>(context) || {};
const obfuscationResult = JavaScriptObfuscator.obfuscate(
sourceCode,
{
...options,
ignoreRequireImports: true
ignoreRequireImports: true,
inputFileName: relativePathOfModule,
sourceMapMode: 'separate'
}
);

Expand Down
Loading

0 comments on commit c04961d

Please sign in to comment.