Skip to content
This repository was archived by the owner on Apr 16, 2019. It is now read-only.

Commit de2779a

Browse files
committed
feat: add cssModule support option, default close it
closes #50 #48
1 parent 2dbc7cc commit de2779a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ see [#3](https://github.com/shepherdwind/css-hot-loader/issues/3).
117117

118118
Force reload all css file.
119119

120+
#### cssModule
121+
122+
When this option is opened, every time you modify the css file, the js file will
123+
reload too. Default closed, this option use with css module.
124+
125+
see [!47](https://github.com/shepherdwind/css-hot-loader/pull/47)
126+
120127
### How
121128

122129

examples/css-modules/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config = { // config object
1717
{
1818
test: /\.module\.css/,
1919
use: [
20-
'css-hot-loader',
20+
'css-hot-loader?cssModule=true',
2121
MiniCssExtractPlugin.loader,
2222
{
2323
loader: 'css-loader',

loader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ module.exports = function(content) {
1111
loaderUtils.getOptions(this)
1212
);
1313

14+
const accept = options.cssModule ? '' : 'module.hot.accept(undefined, cssReload);';
1415
return content + `
1516
if(module.hot) {
1617
// ${Date.now()}
1718
var cssReload = require(${loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'hotModuleReplacement.js'))})(module.id, ${JSON.stringify(options)});
1819
module.hot.dispose(cssReload);
20+
${accept};
1921
}
2022
`;
2123
};

0 commit comments

Comments
 (0)