@@ -12,6 +12,8 @@ const PLUGIN_NAME: PluginName = "react";
12
12
13
13
type BuildSystem = "vite" | "react-scripts" ;
14
14
15
+ type BuildMode = "development" | "production" ;
16
+
15
17
type ViteConfig = {
16
18
configFile ?: string ; // Path to vite.config.[js|ts]
17
19
} ;
@@ -143,17 +145,18 @@ class ServerlessReact {
143
145
144
146
this . log = new Log ( options ) ;
145
147
146
- console . log ( "!!!! process.env" , process . env ) ;
147
-
148
148
this . hooks = {
149
149
initialize : async ( ) => { } ,
150
150
"before:offline:start" : async ( ) => {
151
151
this . log . verbose ( "before:offline:start" ) ;
152
- await this . build ( this . pluginConfig . reloadHandler || false ) ;
152
+ await this . build (
153
+ "development" ,
154
+ this . pluginConfig . reloadHandler || false
155
+ ) ;
153
156
} ,
154
157
"before:package:createDeploymentArtifacts" : async ( ) => {
155
158
this . log . verbose ( "before:package:createDeploymentArtifacts" ) ;
156
- await this . build ( false ) ;
159
+ await this . build ( "production" , false ) ;
157
160
} ,
158
161
} ;
159
162
}
@@ -239,24 +242,25 @@ class ServerlessReact {
239
242
return buildSystem ;
240
243
}
241
244
242
- build = async ( watch : boolean ) : Promise < void > => {
245
+ build = async ( mode : BuildMode , watch : boolean ) : Promise < void > => {
243
246
if ( this . buildSystem === "vite" ) {
244
- await this . buildWithVite ( watch ) ;
247
+ await this . buildWithVite ( mode , watch ) ;
245
248
}
246
249
247
250
if ( this . buildSystem === "react-scripts" ) {
248
- const { config, compiler } = await this . buildWithWebpack ( ) ;
251
+ const { config, compiler } = await this . buildWithWebpack ( mode ) ;
249
252
if ( watch ) {
250
253
await this . watchWebpack ( config , compiler ) ;
251
254
}
252
255
}
253
256
} ;
254
257
255
- buildWithVite = async ( watch : boolean ) : Promise < void > => {
258
+ buildWithVite = async ( mode : BuildMode , watch : boolean ) : Promise < void > => {
256
259
const vite = await import ( "vite" ) ;
257
260
const { entryPoint } = this . pluginConfig ;
258
261
259
262
await vite . build ( {
263
+ mode,
260
264
configFile : this . pluginConfig . vite ?. configFile ,
261
265
build : {
262
266
outDir : this . outputPath ,
@@ -268,12 +272,14 @@ class ServerlessReact {
268
272
} ) ;
269
273
} ;
270
274
271
- buildWithWebpack = async ( ) : Promise < {
275
+ buildWithWebpack = async (
276
+ mode : BuildMode
277
+ ) : Promise < {
272
278
config : WebpackConfiguration ;
273
279
compiler : WebpackCompiler ;
274
280
} > => {
275
- process . env . BABEL_ENV = "production" ;
276
- process . env . NODE_ENV = "production" ;
281
+ process . env . BABEL_ENV = mode ;
282
+ process . env . NODE_ENV = mode ;
277
283
278
284
require ( path . join (
279
285
this . serverlessConfig . servicePath ,
0 commit comments