33const { resolve} = require ( 'path' ) ;
44const { DefinePlugin} = require ( 'webpack' ) ;
55const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
6+ const ReactRefreshWebpackPlugin = require ( '@pmmmwh/react-refresh-webpack-plugin' ) ;
67
78const NODE_ENV = process . env . NODE_ENV ;
89if ( ! NODE_ENV ) {
910 console . error ( 'NODE_ENV not set' ) ;
1011 process . exit ( 1 ) ;
1112}
13+ const __DEV__ = NODE_ENV === 'development' ;
1214
1315const TARGET = process . env . TARGET ;
1416if ( ! TARGET ) {
1517 console . error ( 'TARGET not set' ) ;
1618 process . exit ( 1 ) ;
1719}
20+ const shouldUseDevServer = TARGET === 'local' ;
1821
1922const builtModulesDir = resolve ( __dirname , '..' , '..' , 'build' , 'node_modules' ) ;
2023
21- const __DEV__ = NODE_ENV === 'development' ;
22-
2324const imageInlineSizeLimit = 10000 ;
2425
2526const config = {
@@ -32,6 +33,7 @@ const config = {
3233 alias : {
3334 react : resolve ( builtModulesDir , 'react' ) ,
3435 'react-dom' : resolve ( builtModulesDir , 'react-dom' ) ,
36+ 'react-refresh' : resolve ( builtModulesDir , 'react-refresh' ) ,
3537 } ,
3638 } ,
3739 plugins : [
@@ -43,7 +45,8 @@ const config = {
4345 new HtmlWebpackPlugin ( {
4446 title : 'React Concurrent Mode Profiler' ,
4547 } ) ,
46- ] ,
48+ shouldUseDevServer && new ReactRefreshWebpackPlugin ( ) ,
49+ ] . filter ( Boolean ) ,
4750 module : {
4851 rules : [
4952 {
@@ -56,6 +59,9 @@ const config = {
5659 'react-devtools-shared' ,
5760 'babel.config.js' ,
5861 ) ,
62+ plugins : shouldUseDevServer
63+ ? [ resolve ( builtModulesDir , 'react-refresh/babel' ) ]
64+ : [ ] ,
5965 } ,
6066 } ,
6167 {
@@ -87,7 +93,7 @@ const config = {
8793 } ,
8894} ;
8995
90- if ( TARGET === 'local' ) {
96+ if ( shouldUseDevServer ) {
9197 config . devServer = {
9298 hot : true ,
9399 port : 8080 ,
0 commit comments