Skip to content

Commit b241a50

Browse files
fixing HMR
1 parent c542197 commit b241a50

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "extract-css-chunks-webpack-plugin",
3-
"version": "0.0.0-placeholder",
3+
"version": "3.0.4-beta.1",
44
"author": "James Gillmore <james@faceyspacey.com>",
55
"contributors": [
66
"Zack Jackson <zackary.l.jackson@gmail.com> (https://github.com/zackljackson)"
@@ -18,7 +18,7 @@
1818
"start": "npm run build -- -w",
1919
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
2020
"clean": "del-cli dist",
21-
"lint": "eslint --cache --fix src test",
21+
"lint": "eslint --cache --fix src",
2222
"prebuild": "npm run clean",
2323
"prepublish": "npm run build",
2424
"security": "nsp check",

src/index.js

+19-21
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,29 @@ class ExtractCssChunks {
146146
}
147147

148148
apply(compiler) {
149-
if (process.env.NODE_ENV === 'development') {
150-
try {
151-
const isHOT = isHMR(compiler);
152-
153-
if (isHOT && compiler.options.module && compiler.options.module.rules) {
154-
const updatedRules = compiler.options.module.rules.reduce((rules, rule) => {
155-
if (rule.use && Array.isArray(rule.use)) {
156-
const isMiniCss = rule.use.some((l) => {
157-
const needle = l.loader || l;
158-
return needle.includes(pluginName);
159-
});
160-
if (isMiniCss) {
161-
rule.use.unshift(hotLoader);
162-
}
149+
try {
150+
const isHOT = this.options.hot ? true : isHMR(compiler);
151+
152+
if (isHOT && compiler.options.module && compiler.options.module.rules) {
153+
const updatedRules = compiler.options.module.rules.reduce((rules, rule) => {
154+
if (rule.use && Array.isArray(rule.use)) {
155+
const isMiniCss = rule.use.some((l) => {
156+
const needle = l.loader || l;
157+
return needle.includes(pluginName);
158+
});
159+
if (isMiniCss) {
160+
rule.use.unshift(hotLoader);
163161
}
164-
rules.push(rule);
162+
}
163+
rules.push(rule);
165164

166-
return rules;
167-
}, []);
165+
return rules;
166+
}, []);
168167

169-
compiler.options.module.rules = updatedRules;
170-
}
171-
} catch (e) {
172-
console.error('Something went wrong: contact the author', JSON.stringify(e)); // eslint-disable-line no-console
168+
compiler.options.module.rules = updatedRules;
173169
}
170+
} catch (e) {
171+
console.error('Something went wrong: contact the author', JSON.stringify(e)); // eslint-disable-line no-console
174172
}
175173

176174
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {

test/manual/webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const config = {
2525
new Self({
2626
filename: '[name].css',
2727
chunkFilename: '[contenthash].css',
28+
hot: false
2829
}),
2930

3031
new webpack.NamedModulesPlugin(),

0 commit comments

Comments
 (0)