简体   繁体   中英

Is it possible to remove “sourcesContent” from webpack source maps?

We're working on a large React application and the sourcemaps coming out of our webpack build have reached over 12MB. This seems to be causing problems in the Chrome dev tools where intermittently they fail to parse ( Failed to parse SourceMap error).

We're now loading the source files from the local file system and have altered the webpack config to change the reference location like so:

output: {
  devtoolModuleFilenameTemplate: "file://[absolute-resource-path]",
  devtoolFallbackModuleFilenameTemplate: "file://[absolute-resource-path]?[hash]",
}

This is working fine and the devtools now load the source files from the filesystem, but it doesn't stop them from being compiled into the sourcemaps under "sourcesContent" . I can't find any reference in the docs and there doesn't seem to be an option to turn this off.

Turns out there is a new(ish) undocumented (at time of writing) way to do this with webpack after all, the noSources option of the webpack.SourceMapDevToolPlugin :

const webpackConfig = {
    devtool: false,
    plugins: [
        new webpack.SourceMapDevToolPlugin( {
            moduleFilenameTemplate: 'file://[absolute-resource-path]',
            fallbackModuleFilenameTemplate: 'file://[absolute-resource-path]?[hash]',
            noSources: true
        } ) 
    ],
    ...
};

There is also the nosources-source-map option for devtool in the webpack config, which creates sources without source content ( docs ):

{
  ...
  devtool: "nosources-source-map"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM