@rpcbase/vite 0.76.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +23 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -117,9 +117,27 @@ const rbPackagesNeedingEnvPolyfill = [
117
117
  "@rpcbase/router",
118
118
  ]
119
119
 
120
+ const createRuntimeEnv = ({ env, command, mode, isSsrBuild }) => {
121
+ const isDevCommand = command === "serve"
122
+
123
+ const mergedEnv = {
124
+ ...env,
125
+ }
126
+
127
+ return {
128
+ ...mergedEnv,
129
+ BASE_URL: mergedEnv.BASE_URL ?? "/",
130
+ MODE: mode,
131
+ DEV: isDevCommand,
132
+ PROD: !isDevCommand,
133
+ SSR: Boolean(isSsrBuild),
134
+ }
135
+ }
136
+
120
137
  // https://vite.dev/config/
121
138
  const getBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
122
139
  const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES)
140
+ const runtimeEnv = createRuntimeEnv({ env, command, mode, isSsrBuild })
123
141
 
124
142
  return {
125
143
  clearScreen: false,
@@ -138,9 +156,8 @@ const getBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
138
156
  isProduction && posthogSourcemapsPlugin({}),
139
157
  ].filter(Boolean),
140
158
  define: {
141
- "globalThis.__rb_env__": JSON.stringify({
142
- ...env,
143
- }),
159
+ __vite_env__: runtimeEnv,
160
+ "globalThis.__rb_env__": JSON.stringify(runtimeEnv),
144
161
  },
145
162
  envPrefix: ALLOWED_ENV_PREFIXES,
146
163
  publicDir: path.join(process.cwd(), "./src/client/public"),
@@ -224,6 +241,7 @@ export const extendConfig = (userConfig) => {
224
241
 
225
242
  const getSpecBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
226
243
  const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES)
244
+ const runtimeEnv = createRuntimeEnv({ env, command, mode, isSsrBuild })
227
245
 
228
246
  const input = glob
229
247
  .sync("spec/**/*.spec.ts")
@@ -237,9 +255,8 @@ const getSpecBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
237
255
  return {
238
256
  clearScreen: false,
239
257
  define: {
240
- __vite_env__: {
241
- ...env,
242
- },
258
+ __vite_env__: runtimeEnv,
259
+ "globalThis.__rb_env__": JSON.stringify(runtimeEnv),
243
260
  },
244
261
  envPrefix: ALLOWED_ENV_PREFIXES,
245
262
  build: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/vite",
3
- "version": "0.76.0",
3
+ "version": "0.77.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "scripts": {