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

feat: add cssModule support option, default close it #51

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.4.2 2018-08-15

- feat: add cssModule option [!51](https://github.com/shepherdwind/css-hot-loader/pull/51)

### 1.4.1 2018-07-26

- fix: css module reload issue [#47](https://github.com/shepherdwind/css-hot-loader/pull/47) fix by [@keegan-lillo](https://github.com/keegan-lillo)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ see [#3](https://github.com/shepherdwind/css-hot-loader/issues/3).

Force reload all css file.

#### cssModule

When this option is opened, every time you modify the css file, the js file will
reload too. Default closed, this option use with css module.

see [!47](https://github.com/shepherdwind/css-hot-loader/pull/47) and [!51](https://github.com/shepherdwind/css-hot-loader/pull/51)

### How


Expand Down
2 changes: 1 addition & 1 deletion examples/css-modules/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config = { // config object
{
test: /\.module\.css/,
use: [
'css-hot-loader',
'css-hot-loader?cssModule=true',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
Expand Down
2 changes: 2 additions & 0 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ module.exports = function(content) {
loaderUtils.getOptions(this)
);

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