要压缩/缩小您的 CSS,请使用 optimize-css-assets-webpack-plugin。
在您的配置中,所有样式都添加到<head>,因为style-loader,通过将其设置为ExtractTextPlugin 中的后备,一个名为bundle.css 的css 文件应该可以正确输出。
如果你使用 Webpack 3,这个配置应该可以工作(我在下面的 sn-p 中添加了两个 cmets):
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'bootstrap-loader',
'webpack-hot-middleware/client',
'./src/index'
],
output: {
publicPath: '/dist/'
},
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
localIdentName: '[path][name]--[local]'
}
},
{
loader: 'postcss-loader',
options: { sourceMap: true }
},
{
loader: 'sass-loader',
options: { sourceMap: true }
}
]
})
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"',
},
__DEVELOPMENT__: true
}),
new ExtractTextPlugin('bundle.css'),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
jQuery: 'jquery'
}),
new OptimizeCSSAssetsPlugin({ // minify css
cssProcessorOptions: { // enable css external source maps output, you must set devtool: 'source-map'
map: {
inline: false,
annotation: true
}
}
})
]
};