Skip to content

Commit 1806b72

Browse files
committed
hot module replacement
1 parent 30e2b54 commit 1806b72

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build": "webpack",
8+
"build": "NODE_ENV=production webpack",
99
"lint": "eslint",
1010
"start": "webpack-dev-server --progress"
1111
},
@@ -26,6 +26,7 @@
2626
"mini-css-extract-plugin": "^0.8.0",
2727
"node-sass": "^4.13.0",
2828
"sass-loader": "^8.0.0",
29+
"style-loader": "^1.0.1",
2930
"webpack": "^4.41.2",
3031
"webpack-cli": "^3.3.10",
3132
"webpack-dev-server": "^3.9.0"

webpack.config.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
33
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
44
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
55
const apiMocker = require('connect-api-mocker');
6+
const webpack = require('webpack');
7+
const mode = process.env.NODE_ENV || 'development';
68

79
module.exports = {
8-
mode: 'development',
10+
mode,
911
entry: {
1012
main: './src/app.js'
1113
},
@@ -28,19 +30,22 @@ module.exports = {
2830
})
2931
app.use(apiMocker('/api', 'mocks/api'))
3032
},
31-
host: 'dev.domain.com',
33+
// host: 'dev.domain.com',
3234
stats: 'errors-only',
3335
overlay: true,
3436
port: 8081,
3537
historyApiFallback: true,
38+
proxy: {
39+
'/api': 'localhost:8082'
40+
},
41+
hot: true,
3642
},
37-
watch: false,
3843
module: {
3944
rules: [
4045
{
4146
test: /\.scss$/,
4247
use: [
43-
MiniCssExtractPlugin.loader,
48+
mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
4449
'css-loader',
4550
'sass-loader',
4651
]
@@ -58,12 +63,17 @@ module.exports = {
5863
},
5964
plugins: [
6065
new CleanWebpackPlugin(),
61-
new MiniCssExtractPlugin({
62-
filename: '[name].css',
63-
}),
66+
6467
new HtmlWebpackPlugin({
6568
template: './src/index.html',
6669
hash: true,
6770
}),
71+
...(mode === 'production'
72+
? [
73+
new MiniCssExtractPlugin({ filename: '[name].css' }),
74+
new webpack.HotModuleReplacementPlugin(),
75+
]
76+
: []
77+
)
6878
]
6979
};

0 commit comments

Comments
 (0)