Skip to content

Commit 41def4e

Browse files
committed
set build modes
1 parent 6635cf8 commit 41def4e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/index.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const PLUGIN_NAME: PluginName = "react";
1212

1313
type BuildSystem = "vite" | "react-scripts";
1414

15+
type BuildMode = "development" | "production";
16+
1517
type ViteConfig = {
1618
configFile?: string; // Path to vite.config.[js|ts]
1719
};
@@ -143,17 +145,18 @@ class ServerlessReact {
143145

144146
this.log = new Log(options);
145147

146-
console.log("!!!! process.env", process.env);
147-
148148
this.hooks = {
149149
initialize: async () => {},
150150
"before:offline:start": async () => {
151151
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+
);
153156
},
154157
"before:package:createDeploymentArtifacts": async () => {
155158
this.log.verbose("before:package:createDeploymentArtifacts");
156-
await this.build(false);
159+
await this.build("production", false);
157160
},
158161
};
159162
}
@@ -239,24 +242,25 @@ class ServerlessReact {
239242
return buildSystem;
240243
}
241244

242-
build = async (watch: boolean): Promise<void> => {
245+
build = async (mode: BuildMode, watch: boolean): Promise<void> => {
243246
if (this.buildSystem === "vite") {
244-
await this.buildWithVite(watch);
247+
await this.buildWithVite(mode, watch);
245248
}
246249

247250
if (this.buildSystem === "react-scripts") {
248-
const { config, compiler } = await this.buildWithWebpack();
251+
const { config, compiler } = await this.buildWithWebpack(mode);
249252
if (watch) {
250253
await this.watchWebpack(config, compiler);
251254
}
252255
}
253256
};
254257

255-
buildWithVite = async (watch: boolean): Promise<void> => {
258+
buildWithVite = async (mode: BuildMode, watch: boolean): Promise<void> => {
256259
const vite = await import("vite");
257260
const { entryPoint } = this.pluginConfig;
258261

259262
await vite.build({
263+
mode,
260264
configFile: this.pluginConfig.vite?.configFile,
261265
build: {
262266
outDir: this.outputPath,
@@ -268,12 +272,14 @@ class ServerlessReact {
268272
});
269273
};
270274

271-
buildWithWebpack = async (): Promise<{
275+
buildWithWebpack = async (
276+
mode: BuildMode
277+
): Promise<{
272278
config: WebpackConfiguration;
273279
compiler: WebpackCompiler;
274280
}> => {
275-
process.env.BABEL_ENV = "production";
276-
process.env.NODE_ENV = "production";
281+
process.env.BABEL_ENV = mode;
282+
process.env.NODE_ENV = mode;
277283

278284
require(path.join(
279285
this.serverlessConfig.servicePath,

0 commit comments

Comments
 (0)