javascript-obfuscator / webpack-obfuscator

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

The Plugin is not generating sourcemaps (possible solution) #120

Closed LavaTile closed 3 years ago

LavaTile commented 3 years ago

Reproduction repository: https://github.com/LavaTile/webpack-obfuscator-sourcemap-bug

The plugin is not generating sourcemaps with the config provided in webpack.original.js and webpack.common.js.

I've managed to trace the issue, and it seems like the compilation stage that the Plugin is currently using does not provide sourcemaps for input assets.

Snippet from webpack-obfuscator/plugin/index.ts:

    private extractSourceAndSourceMap(asset: any): { inputSource: string, inputSourceMap: RawSourceMap } {
        if (asset.sourceAndMap) {
            const { source, map } = asset.sourceAndMap();
            return { inputSource: source, inputSourceMap: map };
        } else {
            return {
                inputSource: asset.source(),
                inputSourceMap: asset.map()
            }
        }
    }

With the current compilation stage of PROCESS_ASSETS_STAGE_SUMMARIZE, the return value of inputSourceMap is always null. This means that the plugin never merges the sourcemaps generated during obfuscation with the input sourcemaps.

If the compilation stage is changed to PROCESS_ASSETS_STAGE_DEV_TOOLING, then inputSourceMaps is defined, sourcemaps are merged as expected and correct (usable) .map files are written to the output directory.

This is what I've done in the forked LavaTile/webpack-obfuscator repository (used in webpack.patched.js)

Outputs of both original and patched version of the library can be found in dist/ and validated using https://sokra.github.io/source-map-visualization/#custom-choose

sanex3339 commented 3 years ago

Please try 3.3.2

LavaTile commented 3 years ago

Source maps now work correctly with 3.3.2, thank you! 👍

markerio commented 9 months ago

As of version 3.5.1, the plugin stopped generating source maps.

We need source maps to be able to debug apps in production.

Any updates on this?