webpack: SourceMap is missing when UglifyJSPlugin is enabled

I’m submitting a bug report

Webpack version: 2.1.0-beta.4

Please tell us about your environment: OSX 10.x

Current behavior: Source map is not generated when new webpack.optimize.UglifyJsPlugin() is used. If I remove UglifyJSPlugin or use webpack version 1.13, it does produce source map.

Expected/desired behavior: Source map should be generated.

  • My config
const path = require('path');
const webpack = require('webpack');
const WebpackNotifierPlugin = require('webpack-notifier');
const styleLintPlugin = require('stylelint-webpack-plugin');

const env = process.env.NODE_ENV;

module.exports = {
    devtool: 'source-map',
    entry: './src',
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'app.js',
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify('production'),
            },
        }),
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.UglifyJsPlugin()
    ],
    module: {
        loaders: [
            { test: /\.js$/, exclude: /node_modules/, loader: 'babel' },
            { test: /\.js$/, exclude: /node_modules/, loader: 'eslint' },
            { test: /\.css$/, exclude: /node_modules/, loader: 'style!css?modules&importLoaders=1&localIdentName=[local]_[hash:base64:5]' },
        ],
    },
};

  • Language: [ES6/7]

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

new webpack.optimize.UglifyJsPlugin({
  sourceMap: true
})

We changed the default, because it’s pretty expensive

Wouldn’t it be better if the plugin detects if a devtool has been set, and toggles sourceMap accordingly as a default?

I just lost an hour to this issue, speaking of expensive 😦

This should respect the devtool setting, or at least detect that devtool is set to produce source maps and emit a warning if the equivalent uglify plugin option is not set.

It would also be nice to mention this in the Building for Production docs, because currently it tells us to enable source maps, then to enable UglifyJS, and neglects to mention that the latter disables the former.

This was happening to me, I had to set the sourceMapFilename

  output: {
    ...
    sourceMapFilename: 'bundle.map'
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true
    })
  ] 

can’t work with UglifyJsPlugin and cheap-module-source-map either, even though I added sourceMap: true

Doesn’t seem to work:

"mappings":"AAAA"