Skip to content

Commit 6f58078

Browse files
committed
Fix HMR by sharing React between bundles via CommonChunk
1 parent 96a7cf7 commit 6f58078

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

dev-helpers/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
<body>
4545
<div id="swagger-editor"></div>
4646

47-
<!-- ./dist/* is just the dist folder.. assets on the root have HMR injected -->
48-
<script src="./swagger-editor-bundle.js"> </script>
49-
<script src="./swagger-editor-standalone-preset.js"> </script>
47+
<script src="/commons.js"> </script>
48+
<script src="/swagger-editor-bundle.js"> </script>
49+
<script src="/swagger-editor-standalone-preset.js"> </script>
5050
<script>
5151
window.onload = function() {
5252
// Webpack outputs library variables with file-names-like-this

make-webpack-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ module.exports = function(options) {
161161

162162
devtool: specialOptions.sourcemaps ? 'cheap-module-source-map' : null,
163163

164-
plugins,
165-
166164
}, options)
167165

166+
completeConfig.plugins = (plugins).concat(options.plugins || [])
167+
168168
return completeConfig
169169
}

webpack-hot-dev-server.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var path = require("path")
2+
var webpack = require('webpack')
3+
24

35
module.exports = require("./make-webpack-config.js")({
46
_special: {
@@ -10,13 +12,19 @@ module.exports = require("./make-webpack-config.js")({
1012
}
1113
},
1214

15+
plugins: [
16+
new webpack.optimize.CommonsChunkPlugin({ name: 'commons' }),
17+
],
18+
1319
entry: {
1420
"swagger-editor-bundle": [
1521
'./src/index.js'
1622
],
1723
'swagger-editor-standalone-preset': [
1824
'./src/standalone/index.js'
19-
]
25+
],
26+
'commons': ['react']
27+
2028
},
2129

2230
output: {
@@ -32,6 +40,7 @@ module.exports = require("./make-webpack-config.js")({
3240
devServer: {
3341
port: 3200,
3442
path: path.join(__dirname, "dev-helpers"),
43+
contentBase: path.join(__dirname, "dev-helpers"),
3544
publicPath: "/",
3645
noInfo: true,
3746
colors: true,

0 commit comments

Comments
 (0)