|
2 | 2 | // https://v2.quasar.dev/quasar-cli-vite/quasar-config-file |
3 | 3 |
|
4 | 4 | import { defineConfig } from "#q-app/wrappers"; |
| 5 | +import { isNullOrWhitespace } from "src/util/string_util"; |
5 | 6 | import packageSpec from "./package.json"; |
6 | 7 |
|
7 | 8 | // import checker from "vite-plugin-checker"; |
8 | 9 | // import vueDevTools from "vite-plugin-vue-devtools"; |
9 | 10 |
|
10 | | -const FLAG_ENABLE_VUE_DEV_TOOLS: boolean = false; |
| 11 | +const FLAG_ENABLE_VUE_DEV_TOOLS: boolean = false as const; |
11 | 12 |
|
12 | | -const PUBLIC_BASE_PATH: string = "/"; |
| 13 | +function resolvePublicBasePath(): string { |
| 14 | + let p = process.env.Q_PUBLIC_BASE_PATH; |
| 15 | + |
| 16 | + if (isNullOrWhitespace(p)) { |
| 17 | + // npm exposes `npm_config_*` env vars for `npm run build -- --publicPath=/foo` |
| 18 | + p = process.env.npm_config_qpublicbasepath; |
| 19 | + } |
| 20 | + |
| 21 | + if (isNullOrWhitespace(p)) { |
| 22 | + p = "/"; |
| 23 | + } |
| 24 | + |
| 25 | + // Ensure we always have a leading slash for Vite's base path resolution |
| 26 | + p = p && p.startsWith("/") ? p : `/${p}`; |
| 27 | + |
| 28 | + if (p !== "/") { |
| 29 | + console.log(`Q_PUBLIC_BASE_PATH is '${p}'`); |
| 30 | + } |
| 31 | + |
| 32 | + return p; |
| 33 | +} |
| 34 | + |
| 35 | +const Q_PUBLIC_BASE_PATH: string = resolvePublicBasePath(); |
13 | 36 |
|
14 | 37 | export default defineConfig((ctx) => { |
15 | 38 | console.log("\nquasar.config.ts: defineConfig(..): QuasarContext >>", ctx, "<< QuasarContext"); |
@@ -70,7 +93,7 @@ export default defineConfig((ctx) => { |
70 | 93 |
|
71 | 94 | // rebuildCache: true, // rebuilds Vite/linter/etc cache on startup |
72 | 95 |
|
73 | | - publicPath: PUBLIC_BASE_PATH, |
| 96 | + publicPath: Q_PUBLIC_BASE_PATH, |
74 | 97 | // analyze: true, |
75 | 98 | env: { |
76 | 99 | PACKAGE_NAME: packageSpec.name, |
@@ -201,7 +224,7 @@ export default defineConfig((ctx) => { |
201 | 224 | // manifestFilename: 'manifest.json', |
202 | 225 | extendManifestJson(json: unknown) { |
203 | 226 | (json as Record<string, string>).short_name = packageSpec.productName; |
204 | | - (json as Record<string, string>).start_url = PUBLIC_BASE_PATH; |
| 227 | + (json as Record<string, string>).start_url = Q_PUBLIC_BASE_PATH; |
205 | 228 | }, |
206 | 229 | // useCredentialsForManifestTag: true, |
207 | 230 | // injectPwaMetaTags: false, |
|
0 commit comments