Skip to content

Commit 91ad1e4

Browse files
Support hot as first class option.
Still falls back to `process.env.NODE_ENV` check if no `hot` option is given.
1 parent ada40f5 commit 91ad1e4

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ ExtractTextPlugin.prototype.extract = function(options) {
189189
} else if(!Array.isArray(before)) {
190190
before = [before];
191191
}
192-
options = mergeOptions({omit: before.length, remove: true}, options);
192+
options = mergeOptions({
193+
omit: before.length,
194+
remove: true,
195+
hot: !process.env.NODE_ENV || (process.env.NODE_ENV === "development")
196+
}, options);
193197
delete options.loader;
194198
delete options.use;
195199
delete options.fallback;
@@ -278,7 +282,7 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
278282

279283
// HMR: inject file name into corresponding javascript modules in order to trigger
280284
// appropriate hot module reloading of CSS
281-
if (process.env.NODE_ENV === 'development') {
285+
if (options.hot) {
282286
compilation.plugin("before-chunk-assets", function() {
283287
extractedChunks.forEach(function(extractedChunk) {
284288
forEachChunkModule(extractedChunk, function(module) {

loader.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ var LimitChunkCountPlugin = require("webpack/lib/optimize/LimitChunkCountPlugin"
1515
var NS = fs.realpathSync(__dirname);
1616

1717
module.exports = function(source) {
18-
if (process.env.NODE_ENV !== 'development') return source
18+
var hot = "hot" in query ? query.hot : (!process.env.NODE_ENV || process.env.NODE_ENV === "development");
19+
if (!hot) return source
1920

2021
// We need to always require hotModuleReplacement.js for HMR to work in a wierd scenario
2122
// where only one css file is imported. Otherwise HMR breaks when modules are disposed.
@@ -59,6 +60,7 @@ module.exports.pitch = function(request) {
5960
filename: childFilename,
6061
publicPath: publicPath || this._compilation.outputOptions.publicPath,
6162
};
63+
var hot = "hot" in query ? query.hot : (!process.env.NODE_ENV || process.env.NODE_ENV === "development");
6264
var childCompiler = this._compilation.createChildCompiler("extract-text-webpack-plugin", outputOptions);
6365
childCompiler.apply(new NodeTemplatePlugin());
6466
childCompiler.apply(new LibraryTemplatePlugin(null, "commonjs2"));
@@ -139,7 +141,7 @@ module.exports.pitch = function(request) {
139141
//
140142
// All we need is a date that changes during dev, to trigger a reload since
141143
// hashes generated based on the file contents are what trigger HMR.
142-
if (process.env.NODE_ENV === 'development') {
144+
if (hot) {
143145
const pathVar = publicPath ?
144146
`"${publicPath}"` : "__wepback_public_path__";
145147
resultSource += `

schema/loader-schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
"filename": { "type": "string" },
1212
"use": { "type": ["string", "array", "object"] },
1313
"publicPath": { "type": "string" },
14+
"hot": { "type": "boolean" },
1415

1516
// deprecated
1617
"fallbackLoader": { "type": ["string", "array", "object"] },

schema/plugin-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
"publicPath": {
4242
"description": "",
4343
"type": "string"
44+
},
45+
"hot": {
46+
"description": "Enable HMR",
47+
"type": "boolean"
4448
}
4549
}
4650
}

0 commit comments

Comments
 (0)