Adding class to `styleName` and then adding class to CSS file does not work with HMR
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- javascript, react, sass, webpack
- 领域
- build-system, frontend, tooling
调研方向
从提供的 webpack 配置开始,重点检查 react-css-modules 的 HMR 设置和 SCSS loader 链。重现添加 styleName 类,然后在样式表中定义该类的过程,并跟踪样式表的更改是否传递到了模块更新。完成的标准是:仅编辑 CSS 就能更新正在运行的页面,而无需重新保存 JavaScript 文件。
由索引模型根据 Issue 内容生成。
描述
I have this all setup and working and HMR will work except for in one use case. If you first add a class to styleName and then add the class to your css file HMR will not work. You need to go back to the JS file and re-save that file. This is the case no matter what handleMissingStyleName is set to. I have tried changing a number of settings in my Webpack config, but no luck. Any ideas are greatly appreciated. This is my Webpack config if that helps:
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const WriteFilePlugin = require('write-file-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
module.exports = (env, argv) => {
return {
context: path.resolve(__dirname, 'src'),
entry: './index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'module.min.js'
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: false
}),
new OptimizeCSSAssetsPlugin({})
]
},
resolve: {
alias: {
react: 'preact-compat',
'react-dom': 'preact-compat',
'create-react-class': 'preact-compat/lib/create-react-class',
'react-dom-factories': 'preact-compat/lib/react-dom-factories'
}
},
module: {
rules: [
{
test: /\.scss$/,
use: [
argv.mode !== 'production'
? 'style-loader'
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: argv.mode === 'production' ? false : true,
importLoader: 2,
modules: true,
localIdentName:
argv.mode !== 'production'
? '[local]-[hash:base64]'
: '[hash:base64]'
}
},
{
loader: 'resolve-url-loader'
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: [
require('autoprefixer')({
browsers: ['last 4 versions']
})
]
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
data: '@import "variables"; @import "mixins";',
includePaths: [path.resolve(__dirname, './src/style')]
}
}
]
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-class-properties',
['transform-react-jsx', { pragma: 'h' }],
[
'react-css-modules',
{
context: path.resolve(__dirname, 'src'),
webpackHotModuleReloading: true,
handleMissingStyleName: 'ignore',
generateScopedName:
argv.mode !== 'production'
? '[local]-[hash:base64]'
: '[hash:base64]',
filetypes: {
'.scss': {
syntax: 'postcss-scss'
}
}
}
]
]
}
}
},
{
test: /\.json$/,
use: 'json-loader'
},
{
test: /\.(xml|html|txt|md)$/,
use: 'raw-loader'
},
{
test: /\.(woff2?|ttf|eot|jpe?g|png|gif)(\?.*)?$/i,
use:
argv.mode === 'production'
? 'file-loader?name=[name].[ext]'
: 'url-loader'
},
{
test: /\.svg$/,
oneOf: [
{
include: [/css|non-inline-svg/],
use:
argv.mode === 'production'
? 'file-loader?name=[name].[ext]'
: 'url-loader'
},
{
exclude: [/css|non-inline-svg/],
loader: 'svg-inline-loader'
}
]
}
]
},
plugins: [
new CleanWebpackPlugin(['build/**']),
new HtmlWebpackPlugin({
template: './index.html',
minify: { collapseWhitespace: true }
}),
new HtmlWebpackPlugin({
template: './module.html',
filename: 'module.html',
inject: false,
minify: { collapseWhitespace: true }
}),
new WriteFilePlugin(),
new MiniCssExtractPlugin({
filename: 'module.min.css'
}),
new CopyWebpackPlugin([
{ from: './manifest.json', to: './' },
{ from: './favicon.ico', to: './' }
])
],
devServer: {
port: process.env.PORT || 8080,
host: 'localhost',
publicPath: '/',
contentBase: './src',
historyApiFallback: true,
open: true,
openPage: ''
}
}
}
- 主要语言
- JavaScript
- 星标
- 2k
- 派生
- 159
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
gajus/babel-plugin-react-css-modules 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 35/100
gajus/babel-plugin-react-css-modules#309 · 1 个 reaction ·
-
doesn't work with windicss可能已有人在做 @lili21 于 1775 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 20/100
gajus/babel-plugin-react-css-modules#306 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 35/100
gajus/babel-plugin-react-css-modules#304 · 7 条评论 · 1 个 reaction ·
查看 gajus/babel-plugin-react-css-modules 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
apache/rocketmq-dashboard#7242 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
mihai-vlc/sublime-jsfmt#56 ·
-
Bug v3
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
swc-project/swc#12576 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复