Skip to content

Commit 178e6d5

Browse files
committed
Closes #1, enables HMR. Style HMR is not supported in Webpack 4 yet, but MiniCssExtractPlugin has plan to support it. See webpack-contrib/mini-css-extract-plugin#34
1 parent 4544407 commit 178e6d5

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

app/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import app from './routes'
22

3+
app.use((state, emitter) => {
4+
state.count = 0
5+
})
6+
37
app.mount('body')
8+
9+
if (module.hot) {
10+
module.hot.accept()
11+
}

package-lock.json

+10-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"prod": "NODE_ENV=production node ./server/prod.js",
1111
"test": "echo \"Error: no test specified\" && exit 1"
1212
},
13-
"keywords": ["choo", "ssr", "express"],
13+
"keywords": [
14+
"choo",
15+
"ssr",
16+
"express"
17+
],
1418
"author": "Poyu Chen <[email protected]>",
1519
"license": "MIT",
1620
"repository": {
@@ -27,7 +31,7 @@
2731
"babel-loader": "^7.1.4",
2832
"babel-preset-env": "^1.7.0",
2933
"css-loader": "^0.28.11",
30-
"extract-text-webpack-plugin": "^4.0.0-beta.0",
34+
"mini-css-extract-plugin": "^0.4.0",
3135
"val-loader": "^1.1.0",
3236
"webpack": "^4.12.0",
3337
"webpack-cli": "^3.0.6",

webpack.config.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path')
22
const webpack = require('webpack')
3-
const ExtractTextPlugin = require('extract-text-webpack-plugin')
3+
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
44
const ManifestPlugin = require('webpack-manifest-plugin')
55

66
const babelOptions = {
@@ -15,7 +15,7 @@ module.exports = {
1515
style: './app/main.css'
1616
},
1717
output: {
18-
filename: '[name].[chunkhash:8].js',
18+
filename: '[name].[hash:8].js',
1919
path: path.resolve(__dirname, 'dist')
2020
},
2121
module: {
@@ -31,14 +31,10 @@ module.exports = {
3131
},
3232
{
3333
test: /\.css$/,
34-
use: ExtractTextPlugin.extract({
35-
use: [
36-
{
37-
loader: 'css-loader',
38-
options: { modules: false, importLoaders: 1 }
39-
}
40-
]
41-
})
34+
use: [
35+
MiniCssExtractPlugin.loader,
36+
'css-loader'
37+
]
4238
},
4339
{
4440
// loads all assets from assets/ for use by common/assets.js
@@ -48,12 +44,15 @@ module.exports = {
4844
]
4945
},
5046
plugins: [
51-
new ExtractTextPlugin({
52-
filename: 'style.[hash:8].css'
47+
new MiniCssExtractPlugin({
48+
filename: 'style.[chunkhash:8].css'
5349
}),
50+
new webpack.NamedModulesPlugin(),
51+
new webpack.HotModuleReplacementPlugin(),
5452
new ManifestPlugin()
5553
],
5654
devServer: {
57-
before: require('./server/dev')
55+
before: require('./server/dev'),
56+
hot: true
5857
}
5958
}

0 commit comments

Comments
 (0)