1
我一直在試圖理解webpack中的「生產模式」。從我現在在webpack 2中你可以運行webpack -p
,但這並不像功能豐富。 我的設置,我從1的WebPack結轉是像這樣:如何在我的webpack設置中使用'extract-text-plugin'
var config = {
context: __dirname + '/app',
entry: './index.js',
output: {
path: __dirname + '/app',
filename: 'bundle.js'
},
plugins: [
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.html$/,
threshold: 10240,
minRatio: 0.8
}),
new webpack.ProvidePlugin({
moment: "moment"
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader',
exclude: /node_modules/
},
{
test: /\.html$/,
loader: 'raw-loader',
exclude: /node_modules/
}
]
}
};
if (process.env.NODE_ENV === 'production') {
config.output.path = __dirname + '/dist';
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
config.plugins.push(new ExtractTextPlugin("styles.css"));
config.module.loaders({
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "style-loader!css-loader!sass-loader"
})
})
}
module.exports = config;
我真的想這樣是在生產模式下使用extract-text-plugin
,我已經嘗試以下操作:
if (process.env.NODE_ENV === 'production') {
config.output.path = __dirname + '/dist';
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
config.plugins.push(new ExtractTextPlugin("styles.css"));
config.module.loaders({
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "style-loader!css-loader!sass-loader"
})
})
}
我收到以下錯誤:
config.loaders({
^
TypeError: config.loaders is not a function