Skip to content

Commit 62188a6

Browse files
committed
fix: pnpm check messing up dev server
1 parent fed6e6e commit 62188a6

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite dev",
8-
"build": "vite build",
9-
"preview": "vite preview",
8+
"build": "cross-env BUILD_ENV=production vite build",
9+
"preview": "cross-env BUILD_ENV=production vite preview",
1010
"prepare": "svelte-kit sync || echo '' && husky",
1111
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1212
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
@@ -38,6 +38,7 @@
3838
"boxen": "^8.0.1",
3939
"chalk": "^5.6.2",
4040
"clsx": "^2.1.1",
41+
"cross-env": "^10.1.0",
4142
"eslint": "^10.2.1",
4243
"eslint-config-prettier": "^10.1.8",
4344
"eslint-plugin-compat": "^7.0.1",
@@ -82,4 +83,4 @@
8283
"defaults and fully supports es6-module"
8384
],
8485
"packageManager": "pnpm@10.33.2"
85-
}
86+
}

pnpm-lock.yaml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svelte.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import { loadEnv } from 'vite';
99
const isGithubActions = process.env.GITHUB_ACTIONS === 'true';
1010
const isCloudflare = process.env.CF_PAGES === '1';
1111
const isDocker = process.env.DOCKER === 'true';
12-
const mode = process.env.NODE_ENV;
12+
// Don't trust NODE_ENV — tools like svelte-check load this file mid-process and
13+
// can have NODE_ENV='production' set by transitively-imported plugins (vite,
14+
// vite-plugin-svelte) even though no production build is actually happening.
15+
// `pnpm build`/`pnpm preview` set BUILD_ENV=production explicitly via cross-env;
16+
// CI/Cloudflare/Docker each have their own flag.
17+
const isProductionBuild =
18+
isGithubActions || isCloudflare || isDocker || process.env.BUILD_ENV === 'production';
19+
const mode = isProductionBuild ? 'production' : 'development';
1320

1421
const dotenv = { ...process.env, ...loadEnv(mode, process.cwd(), 'PUBLIC_') };
1522

0 commit comments

Comments
 (0)