@@ -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 ) {
0 commit comments