@@ -3,9 +3,11 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
33const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' )
44const { CleanWebpackPlugin } = require ( 'clean-webpack-plugin' )
55const apiMocker = require ( 'connect-api-mocker' ) ;
6+ const webpack = require ( 'webpack' ) ;
7+ const mode = process . env . NODE_ENV || 'development' ;
68
79module . 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 : / \. s c s s $ / ,
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