我可以使css 模块工作,但不能在热重载中工作。
首次加载时,样式以应有的方式显示:
但是在对 css 文件进行更改后,它会中断,并且需要完全重新加载:
我正在使用 css 模块,如下所示:
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pack = {
entry: [
path.join(__dirname, 'src/app/index.js'),
],
output: {
path: path.join(__dirname, '/dist/'),
filename: '[name].js',
publicPath: '/',
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/app/index.html',
inject: 'body',
filename: 'index.html',
}),
],
module: {
loaders: [
{
test: /\.css$/,
include: /src\/app/,
loaders: [
'style?sourceMap',
'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
],
},
{
test: /\.js?$/,
include: /src\/app/,
loader: 'babel',
},
{
test: /\.woff(2)?(\?[a-z0-9#=&.]+)?$/,
loader: 'url?limit=10000&mimetype=application/font-woff',
},
{
test: /\.(ttf|eot|svg)(\?[a-z0-9#=&.]+)?$/,
loader: 'file',
},
],
},
};
module.exports = pack;
webpack.development.config.js
const webpack = require('webpack');
const pack = require('./webpack.config');
pack.entry.unshift('react-hot-loader/patch');
pack.entry.unshift('webpack/hot/only-dev-server');
pack.entry.unshift('webpack-dev-server/client?http://localhost:3000');
pack.plugins.push(new webpack.HotModuleReplacementPlugin());
pack.plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}));
module.exports = pack;
正如我所注意到的,它尝试在组件中获取的 css 类仍然相同,不应该为每个文件更改/重新加载生成一个新的哈希吗?