Skip to content

Commit 2fcc86d

Browse files
committed
chore: make sure to use production env when building for production
1 parent b64db65 commit 2fcc86d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ node_modules_bak/
6767

6868
# dotenv environment variables file
6969
.env
70+
.env*
7071

7172
#vs code
7273
.vscode/*

frontend/vite.config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { defineConfig, mergeConfig } from "vite";
22
import injectHTML from "vite-plugin-html-inject";
33
import autoprefixer from "autoprefixer";
4-
import "dotenv/config";
4+
import { config as dotenvConfig } from "dotenv";
55
import PROD_CONFIG from "./vite.config.prod";
66
import DEV_CONFIG from "./vite.config.dev";
77
import MagicString from "magic-string";
88
import { Fonts } from "./src/ts/constants/fonts";
99

10+
// Load environment variables based on NODE_ENV
11+
const envFile =
12+
process.env.NODE_ENV === "production" ? ".env.production" : ".env";
13+
dotenvConfig({ path: envFile });
14+
1015
/** @type {import("vite").UserConfig} */
1116
const BASE_CONFIG = {
1217
plugins: [
@@ -63,8 +68,13 @@ const BASE_CONFIG = {
6368

6469
export default defineConfig(({ command }) => {
6570
if (command === "build") {
71+
const envFileName =
72+
process.env.NODE_ENV === "production" ? ".env.production" : ".env";
6673
if (process.env.RECAPTCHA_SITE_KEY === undefined) {
67-
throw new Error(".env: RECAPTCHA_SITE_KEY is not defined");
74+
throw new Error(`${envFileName}: RECAPTCHA_SITE_KEY is not defined`);
75+
}
76+
if (process.env.SENTRY && process.env.SENTRY_AUTH_TOKEN === undefined) {
77+
throw new Error(`${envFileName}: SENTRY_AUTH_TOKEN is not defined`);
6878
}
6979
return mergeConfig(BASE_CONFIG, PROD_CONFIG);
7080
} else {

packages/release/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ const buildProject = () => {
179179

180180
if (isFrontend && !isBackend) {
181181
runProjectRootCommand(
182-
"SENTRY=1 npx turbo lint test check-assets build --filter @monkeytype/frontend --force",
182+
"NODE_ENV=production SENTRY=1 npx turbo lint test check-assets build --filter @monkeytype/frontend --force",
183183
);
184184
} else if (isBackend && !isFrontend) {
185185
runProjectRootCommand(
186-
"SENTRY=1 npx turbo lint test build --filter @monkeytype/backend --force",
186+
"NODE_ENV=production SENTRY=1 npx turbo lint test build --filter @monkeytype/backend --force",
187187
);
188188
} else {
189189
runProjectRootCommand(
190-
"SENTRY=1 npx turbo lint test check-assets build --force",
190+
"NODE_ENV=production SENTRY=1 npx turbo lint test check-assets build --force",
191191
);
192192
}
193193
};

0 commit comments

Comments
 (0)