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]

Author: Fantashit

7 thoughts on “SourceMap is missing when UglifyJSPlugin is enabled

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

    We changed the default, because it’s pretty expensive

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

  3. 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.

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

  5. 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.

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

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

Comments are closed.