javascript-obfuscator / webpack-obfuscator

javascript-obfuscator plugin for Webpack
https://github.com/javascript-obfuscator/javascript-obfuscator
BSD 2-Clause "Simplified" License
856 stars 84 forks source link

Support the obfuscation of web worker files #105

Open wxfred opened 3 years ago

wxfred commented 3 years ago

Is it possible to include web worker files, after compilation, they are not in compilation.chunks.

wxfred commented 3 years ago

I simply change a little bit of dist/plugin/index.js, it works, but I'm not sure if there's a potential problem. Looking forward to your update!

//compilation.chunks.forEach(chunk => {
  //chunk.files.forEach((fileName) => {
    for (let fileName in compilation.assets) { // replace 2 lines above
      if (this.options.sourceMap && fileName.toLowerCase().endsWith('.map')) {
        let srcName = fileName.toLowerCase().substr(0, fileName.length - 4);
        if (!this.shouldExclude(srcName)) {
          const transferredSourceMap = transferSourceMap({
            fromSourceMap: sourcemapOutput[srcName],
            toSourceMap: compilation.assets[fileName].source()
          });
          const finalSourcemap = JSON.parse(transferredSourceMap);
          finalSourcemap['sourcesContent'] = JSON.parse(compilation.assets[fileName].source())['sourcesContent'];
          compilation.assets[fileName] = new webpack_sources_1.RawSource(JSON.stringify(finalSourcemap));
        }
        return;
      }
      if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
        return;
      }
      const asset = compilation.assets[fileName];
      const {
        inputSource,
        inputSourceMap
      } = this.extractSourceAndSourceMap(asset);
      const {
        obfuscatedSource,
        obfuscationSourceMap
      } = this.obfuscate(inputSource, fileName, identifiersPrefixCounter);
      if (this.options.sourceMap && inputSourceMap) {
        sourcemapOutput[fileName] = obfuscationSourceMap;
      }
      compilation.assets[fileName] = new webpack_sources_1.RawSource(obfuscatedSource);
      identifiersPrefixCounter++;
    } // replace 2 lines below
  //});
//});
sanex3339 commented 3 years ago

I will try it in the upcoming weeks.

elderapo commented 2 years ago

Any update on this? :eyes: