create-kelpie 0.3.0 → 0.4.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.
- package/package.json +1 -1
- package/templates/vite.config.ts +22 -8
package/package.json
CHANGED
package/templates/vite.config.ts
CHANGED
|
@@ -11,7 +11,7 @@ const projectRoot = fileURLToPath(new URL('./', import.meta.url))
|
|
|
11
11
|
* origin, so the UI runs against same-origin `/v1` in development exactly as it
|
|
12
12
|
* does in production.
|
|
13
13
|
*/
|
|
14
|
-
export default defineConfig(({ mode }) => {
|
|
14
|
+
export default defineConfig(({ mode, command }) => {
|
|
15
15
|
// `loadEnv` rather than `process.env`, because `npm run dev:web` runs `vite`
|
|
16
16
|
// directly and nothing has read `.env` into the environment by then. Reading
|
|
17
17
|
// `process.env.WEB_PORT` here means the port in `.env` is silently ignored and
|
|
@@ -24,6 +24,26 @@ export default defineConfig(({ mode }) => {
|
|
|
24
24
|
// page loads and every `/v1` call times out against the dev server it came
|
|
25
25
|
// from.
|
|
26
26
|
const environment = loadEnv(mode, projectRoot, ['API_', 'WEB_'])
|
|
27
|
+
|
|
28
|
+
const shared = {
|
|
29
|
+
root: fileURLToPath(new URL('./web', import.meta.url)),
|
|
30
|
+
envDir: projectRoot,
|
|
31
|
+
plugins: [react(), tailwindcss()],
|
|
32
|
+
build: {
|
|
33
|
+
outDir: fileURLToPath(new URL('./dist', import.meta.url)),
|
|
34
|
+
emptyOutDir: true,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// A production build writes static files and proxies nothing, so it needs no
|
|
39
|
+
// API port. Demanding one for every invocation breaks any build that runs
|
|
40
|
+
// without a `.env` beside it, which is exactly what a container build is: the
|
|
41
|
+
// image leaves `.env` out because it holds `SECRET_ENCRYPTION_KEY`, and the
|
|
42
|
+
// build then dies over a variable it was never going to read.
|
|
43
|
+
if (command !== 'serve') {
|
|
44
|
+
return shared
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
const apiPort = environment.API_PORT
|
|
28
48
|
|
|
29
49
|
if (apiPort === undefined || apiPort.length === 0) {
|
|
@@ -33,13 +53,7 @@ export default defineConfig(({ mode }) => {
|
|
|
33
53
|
const apiOrigin = `http://localhost:${apiPort}`
|
|
34
54
|
|
|
35
55
|
return {
|
|
36
|
-
|
|
37
|
-
envDir: projectRoot,
|
|
38
|
-
plugins: [react(), tailwindcss()],
|
|
39
|
-
build: {
|
|
40
|
-
outDir: fileURLToPath(new URL('./dist', import.meta.url)),
|
|
41
|
-
emptyOutDir: true,
|
|
42
|
-
},
|
|
56
|
+
...shared,
|
|
43
57
|
server: {
|
|
44
58
|
port: Number(environment.WEB_PORT ?? 5173),
|
|
45
59
|
// Refuse rather than quietly taking the next port. A launcher that was
|