2017-12-02 151 views
4

不可否認,我對source mapswebpack有基本的瞭解。這是我的理解,如果我在我的webpack.config.js文件中正確設置devtools,我應該得到映射到原始代碼的源映射文件。不是由WebPack生成的源地圖

我正在使用下面的配置文件,我沒有得到任何源映射文件。任何想法爲什麼?

var IS_DEV = false; 

var webpack = require('webpack'); 
var path = require("path"); 

// Define plugins needed for production and dev cases 
var _pluginsDev = [ 
    new webpack.ProvidePlugin({ 
     'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch', 
     moment: 'moment', 
     ps: 'perfect-scrollbar' 
    }), 

]; 
var _pluginsProd = [ 
    new webpack.ProvidePlugin({ 
     'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch', 
     moment: 'moment', 
     ps: 'perfect-scrollbar' 
    }), 
    new webpack.DefinePlugin({ 
     'process.env': { 
      'NODE_ENV': JSON.stringify('production') 
     } 
    }), 
    new webpack.optimize.UglifyJsPlugin({ 
     minimize: true, 
     compress: true, 
     output: { comments: false } 
    }) 
]; 

var _devtool = IS_DEV ? 'eval' : 'cheap-module-source-map'; 
var _plugins = IS_DEV ? _pluginsDev : _pluginsProd; 
var _fileName = IS_DEV ? "./build/[name]-bundle.js" : "./dist/[name]-bundle.js"; 

var _bundles = { 
    login: './components/login/login.jsx', 
    home: './components/home/home.jsx' 
}; 

module.exports = { 
    entry: _bundles, 
    output: { 
     path: path.resolve(__dirname, "wwwroot"), 
     publicPath: "/", 
     filename: _fileName 
    }, 
    devtool: _devtool, 
    plugins: _plugins, 
    module: { 
     rules: [ 
      { 
       test: /\.jsx?$/, 
       exclude: /(node_modules|bower_components)/, 
       use: { 
        loader: "babel-loader", 
        options: { 
         presets: ['es2015', 'stage-2', 'stage-0', 'react'] 
        } 
       } 
      } 
     ] 
    }, 
    resolve: { 
     extensions: ['.js', '.jsx'] 
    } 
} 
+0

你使用的是什麼版本的webpack? –

+0

'webpack -v'給我'2.7.0' – Sam

+2

每個文檔,不知道它是否會解決你的問題,'當使用uglifyjs-webpack-plugin時,你必須提供sourceMap:true選項來啓用SourceMap支持。 ' –

回答

7

根據該文件,

當使用uglifyjs-的WebPack-插件,你必須提供sourceMap: 真選項啓用SourceMap支持。