john_omalley
john_omalley

Reputation: 1398

Webpack 2 devtool not working

I'm trying to convert from webpack 1 to 2 but webpack does not seem to be generating a source map file using devtool: 'source-map'. If I run webpack with the below configuration the bundle.js file is created in /public as expected but there is no bundle.js.map file, nor is there an error. With webpack 1 it worked as expected:

const webpack = require('webpack')

module.exports = {
  entry: ['babel-polyfill', './src/index.js'],
  output: {
    path: './public',
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader'
      }
    ]
  },
  devtool: 'source-map',
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
        API_BASE_URL: `"${process.env.API_BASE_URL || '/api/v1'}"`
      }
    }),
    new webpack.optimize.UglifyJsPlugin()
  ]
}

CLI output:

> cross-env NODE_ENV=production webpack
Hash: 738da5a3824ffac20236
Version: webpack 2.2.0
Time: 13819ms
    Asset    Size  Chunks                    Chunk Names
bundle.js  611 kB       0  [emitted]  [big]  main
   [2] ./~/react/react.js 56 bytes {0} [built]

Upvotes: 2

Views: 962

Answers (1)

john_omalley
john_omalley

Reputation: 1398

Looks like if you're using the UglifyJSPlugin source maps are silently disabled unless you re-enable them there:

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

Upvotes: 7

Related Questions