webpack-obfuscator icon indicating copy to clipboard operation
webpack-obfuscator copied to clipboard

Support the obfuscation of web worker files

Open wxfred opened this issue 4 years ago • 3 comments

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

wxfred avatar Jan 10 '21 18:01 wxfred

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
  //});
//});

wxfred avatar Jan 10 '21 18:01 wxfred

I will try it in the upcoming weeks.

sanex3339 avatar Feb 03 '21 20:02 sanex3339

Any update on this? :eyes:

elderapo avatar Dec 09 '21 22:12 elderapo