這裏的設置:如何讓webpack的uglifyjs插件不會破壞sass的源地圖?
package.json
:
{
"dependencies": {
"css-loader": "^0.26.0",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.24.1",
"node-sass": "^3.13.0",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"webpack": "^1.13.3"
}
}
webpack.config.js
:
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './1.js',
output: {
path: 'dist',
filename: 'bundle.js',
},
module: {
loaders: [
{test: /\.sass$/, loader: ExtractTextPlugin.extract('style', 'css?sourceMap!sass?sourceMap')},
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'template.ejs',
}),
new ExtractTextPlugin('[name].css'),
new webpack.optimize.UglifyJsPlugin(),
],
devtool: 'source-map',
};
template.ejs
:
<!doctype html>
<html>
<body>
<div></div>
</body>
</html>
1.js
:
require('./1.sass');
1.sass
:
body
background: #ddd
div
width: 100px
height: 100px
margin: auto
background: #333
然後
$ rm -rf dist/* && ./node_modules/.bin/webpack
而在Chrome中打開http://example.com/dist
。然後去Developer Tools
>Elements tab
。點擊div
,然後點擊div { width: 100px; ... }
塊的鏈接。你會發現自己在第二行。但是當你註釋掉new webpack.optimize.UglifyJsPlugin()
行時,你會像預期的那樣在第3行。我究竟做錯了什麼?