@@ -29,7 +29,7 @@ const cleanFilename = name =>
2929 * @returns  {Promise<import('webpack').Configuration> } 
3030 */ 
3131async  function  clientConfig ( env )  { 
32- 	const  {  isProd ,   source,  src,  cwd  /*, port? */  }  =  env ; 
32+ 	const  {  source,  src,  cwd }  =  env ; 
3333	const  IS_SOURCE_PREACT_X_OR_ABOVE  =  isInstalledVersionPreactXOrAbove ( cwd ) ; 
3434	const  asyncLoader  =  IS_SOURCE_PREACT_X_OR_ABOVE 
3535		? require . resolve ( '@preact/async-loader' ) 
@@ -84,7 +84,7 @@ async function clientConfig(env) {
8484		// copy any static files 
8585		existsSync ( source ( 'assets' ) )  &&  {  from : 'assets' ,  to : 'assets'  } , 
8686		// copy sw-debug 
87- 		! isProd  &&  { 
87+ 		! env . isProd  &&  { 
8888			from : resolve ( __dirname ,  '../../resources/sw-debug.js' ) , 
8989			to : 'sw-debug.js' , 
9090		} , 
@@ -100,7 +100,7 @@ async function clientConfig(env) {
100100		output : { 
101101			path : env . dest , 
102102			publicPath : '/' , 
103- 			filename : isProd  ? '[name].[chunkhash:5].js'  : '[name].js' , 
103+ 			filename : env . isProd  ? '[name].[chunkhash:5].js'  : '[name].js' , 
104104			chunkFilename : '[name].chunk.[chunkhash:5].js' , 
105105		} , 
106106
@@ -143,6 +143,8 @@ async function clientConfig(env) {
143143		plugins : [ 
144144			new  webpack . DefinePlugin ( { 
145145				'process.env.ES_BUILD' : false , 
146+ 				'process.env.ADD_SW' : env . sw , 
147+ 				'process.env.PRERENDER' : env . prerender , 
146148			} ) , 
147149			new  PushManifestPlugin ( env ) , 
148150			...( await  renderHTMLPlugin ( env ) ) , 
@@ -156,14 +158,12 @@ async function clientConfig(env) {
156158	} ; 
157159} 
158160
159- function  getBabelEsmPlugin ( config )  { 
161+ function  getBabelEsmPlugin ( env )  { 
160162	const  esmPlugins  =  [ ] ; 
161- 	if  ( config . esm )  { 
163+ 	if  ( env . esm )  { 
162164		esmPlugins . push ( 
163165			new  BabelEsmPlugin ( { 
164- 				filename : config . isProd 
165- 					? '[name].[chunkhash:5].esm.js' 
166- 					: '[name].esm.js' , 
166+ 				filename : env . isProd  ? '[name].[chunkhash:5].esm.js'  : '[name].esm.js' , 
167167				chunkFilename : '[name].chunk.[chunkhash:5].esm.js' , 
168168				excludedPlugins : [ 'BabelEsmPlugin' ,  'InjectManifest' ] , 
169169				beforeStartExecution : plugins  =>  { 
@@ -196,7 +196,7 @@ function getBabelEsmPlugin(config) {
196196/** 
197197 * @returns  {import('webpack').Configuration } 
198198 */ 
199- function  isProd ( config )  { 
199+ function  isProd ( env )  { 
200200	let  limit  =  200  *  1000 ;  // 200kb 
201201	const  prodConfig  =  { 
202202		performance : Object . assign ( 
@@ -205,14 +205,12 @@ function isProd(config) {
205205				maxAssetSize : limit , 
206206				maxEntrypointSize : limit , 
207207			} , 
208- 			config . pkg . performance 
208+ 			env . pkg . performance 
209209		) , 
210210
211211		plugins : [ 
212212			new  webpack . DefinePlugin ( { 
213- 				'process.env.ADD_SW' : config . sw , 
214- 				'process.env.ESM' : config . esm , 
215- 				'process.env.PRERENDER' : config . prerender , 
213+ 				'process.env.ESM' : env . esm , 
216214			} ) , 
217215			new  SizePlugin ( ) , 
218216		] , 
@@ -252,7 +250,7 @@ function isProd(config) {
252250		} , 
253251	} ; 
254252
255- 	if  ( config [ 'inline-css' ] )  { 
253+ 	if  ( env [ 'inline-css' ] )  { 
256254		prodConfig . plugins . push ( 
257255			new  CrittersPlugin ( { 
258256				preload : 'media' , 
@@ -263,11 +261,11 @@ function isProd(config) {
263261		) ; 
264262	} 
265263
266- 	if  ( config . analyze )  { 
264+ 	if  ( env . analyze )  { 
267265		prodConfig . plugins . push ( new  BundleAnalyzerPlugin ( ) ) ; 
268266	} 
269267
270- 	if  ( config . brotli )  { 
268+ 	if  ( env . brotli )  { 
271269		prodConfig . plugins . push ( 
272270			new  CompressionPlugin ( { 
273271				filename : '[path].br[query]' , 
@@ -283,21 +281,17 @@ function isProd(config) {
283281/** 
284282 * @returns  {import('webpack').Configuration } 
285283 */ 
286- function  isDev ( config )  { 
287- 	const  {  cwd,  src,  refresh  }  =  config ; 
284+ function  isDev ( env )  { 
285+ 	const  {  cwd,  src  }  =  env ; 
288286
289287	return  { 
290288		infrastructureLogging : { 
291289			level : 'info' , 
292290		} , 
293291		plugins : [ 
294292			new  webpack . NamedModulesPlugin ( ) , 
295- 			...( refresh  ? [ new  RefreshPlugin ( ) ]  : [ ] ) , 
296- 			new  webpack . DefinePlugin ( { 
297- 				'process.env.ADD_SW' : config . sw , 
298- 				'process.env.PRERENDER' : config . prerender , 
299- 			} ) , 
300- 		] , 
293+ 			env . refresh  &&  new  RefreshPlugin ( ) , 
294+ 		] . filter ( Boolean ) , 
301295
302296		devServer : { 
303297			hot : true , 
@@ -312,9 +306,9 @@ function isDev(config) {
312306					ignored : [ resolve ( cwd ,  'build' ) ,  resolve ( cwd ,  'node_modules' ) ] , 
313307				} , 
314308			} , 
315- 			https : config . https , 
316- 			port : config . port , 
317- 			host : process . env . HOST  ||  config . host  ||  '0.0.0.0' , 
309+ 			https : env . https , 
310+ 			port : env . port , 
311+ 			host : process . env . HOST  ||  env . host  ||  '0.0.0.0' , 
318312			allowedHosts : 'all' , 
319313			historyApiFallback : true , 
320314			client : { 
0 commit comments