|
1 | 1 | "use strict"; |
2 | 2 |
|
3 | | -let JavaScriptObfuscator: any = require('javascript-obfuscator'), |
4 | | - RawSource: any = require("webpack-sources").RawSource, |
5 | | - SourceMapSource: any = require("webpack-sources").SourceMapSource, |
6 | | - multimatch: any = require('multimatch'), |
7 | | - transferSourceMap = require("multi-stage-sourcemap").transfer; |
| 3 | +import { Compiler } from 'webpack'; |
| 4 | + |
| 5 | +const JavaScriptObfuscator = require('javascript-obfuscator'); |
| 6 | +const RawSource = require("webpack-sources").RawSource; |
| 7 | +const SourceMapSource = require("webpack-sources").SourceMapSource; |
| 8 | +const multimatch = require('multimatch'); |
| 9 | +const transferSourceMap = require("multi-stage-sourcemap").transfer; |
| 10 | + |
| 11 | +type TObject = {[key: string]: any}; |
8 | 12 |
|
9 | 13 | class WebpackObfuscator { |
10 | | - public options: any = {}; |
| 14 | + /** |
| 15 | + * @type {TObject} |
| 16 | + */ |
| 17 | + public options: TObject = {}; |
| 18 | + |
| 19 | + /** |
| 20 | + * @type {string} |
| 21 | + */ |
11 | 22 | public excludes: string[]; |
12 | 23 |
|
13 | 24 | /** |
14 | | - * @param options |
15 | | - * @param excludes |
| 25 | + * @param {TObject} options |
| 26 | + * @param {string | string[]} excludes |
16 | 27 | */ |
17 | | - constructor (options: any, excludes: string|string[]) { |
| 28 | + constructor (options: TObject, excludes: string|string[]) { |
18 | 29 | this.options = options || {}; |
19 | 30 | this.excludes = typeof excludes === 'string' ? [excludes] : excludes || []; |
20 | 31 | } |
21 | 32 |
|
22 | 33 | /** |
23 | | - * @param compiler |
| 34 | + * @param {Compiler} compiler |
24 | 35 | */ |
25 | | - public apply (compiler: any): void { |
| 36 | + public apply (compiler: Compiler): void { |
26 | 37 | compiler.plugin('compilation', (compilation: any) => { |
27 | 38 | compilation.plugin("optimize-chunk-assets", (chunks: any[], callback: () => void) => { |
28 | 39 | let files = []; |
@@ -97,13 +108,7 @@ class WebpackObfuscator { |
97 | 108 | * @returns {boolean} |
98 | 109 | */ |
99 | 110 | private shouldExclude (filePath: string, excludes: string[]): boolean { |
100 | | - for (let exclude of excludes) { |
101 | | - if (multimatch(filePath, exclude).length > 0) { |
102 | | - return true; |
103 | | - } |
104 | | - } |
105 | | - |
106 | | - return false; |
| 111 | + return multimatch(filePath, excludes).length > 0 |
107 | 112 | } |
108 | 113 | } |
109 | 114 |
|
|
0 commit comments