Skip to content

Commit cb4324c

Browse files
committed
Fix up Vite env port handling
1 parent 715c749 commit cb4324c

File tree

14 files changed

+129
-84
lines changed

14 files changed

+129
-84
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Run the component's dev server on :3001
22
# (The Streamlit dev server already runs on :3000)
3-
PORT=3001
3+
VITE_PORT=3001
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { defineConfig, UserConfig } from "vite"
1+
import { defineConfig, loadEnv, UserConfig } from "vite"
22
import react from "@vitejs/plugin-react-swc"
33

44
/**
55
* Vite configuration for Streamlit React Component development
66
*
77
* @see https://vitejs.dev/config/ for complete Vite configuration options
88
*/
9-
export default defineConfig({
10-
base: "./",
11-
plugins: [react()],
12-
server: {
13-
port: process.env.PORT ? parseInt(process.env.PORT) : 3001,
14-
},
15-
build: {
16-
outDir: "build",
17-
},
18-
}) satisfies UserConfig
9+
export default defineConfig(({ mode }) => {
10+
const env = loadEnv(mode, process.cwd())
11+
12+
const port = env.VITE_PORT ? parseInt(env.VITE_PORT) : 3001
13+
14+
return {
15+
base: "./",
16+
plugins: [react()],
17+
server: {
18+
port,
19+
},
20+
build: {
21+
outDir: "build",
22+
},
23+
} satisfies UserConfig
24+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Run the component's dev server on :3001
22
# (The Streamlit dev server already runs on :3000)
3-
PORT=3001
3+
VITE_PORT=3001
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
import { defineConfig, UserConfig } from "vite"
1+
import { defineConfig, loadEnv, UserConfig } from "vite"
2+
import react from "@vitejs/plugin-react-swc"
23

34
/**
4-
* Vite configuration for Streamlit Component development
5+
* Vite configuration for Streamlit React Component development
56
*
67
* @see https://vitejs.dev/config/ for complete Vite configuration options
78
*/
8-
export default defineConfig({
9-
base: "./",
10-
server: {
11-
port: process.env.PORT ? parseInt(process.env.PORT) : 3001,
12-
},
13-
build: {
14-
outDir: "build",
15-
},
16-
}) satisfies UserConfig
9+
export default defineConfig(({ mode }) => {
10+
const env = loadEnv(mode, process.cwd())
11+
12+
const port = env.VITE_PORT ? parseInt(env.VITE_PORT) : 3001
13+
14+
return {
15+
base: "./",
16+
plugins: [react()],
17+
server: {
18+
port,
19+
},
20+
build: {
21+
outDir: "build",
22+
},
23+
} satisfies UserConfig
24+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Run the component's dev server on :3001
22
# (The Streamlit dev server already runs on :3000)
3-
PORT=3001
3+
VITE_PORT=3001
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { defineConfig, UserConfig } from "vite"
1+
import { defineConfig, loadEnv, UserConfig } from "vite"
22
import react from "@vitejs/plugin-react-swc"
33

44
/**
55
* Vite configuration for Streamlit React Component development
66
*
77
* @see https://vitejs.dev/config/ for complete Vite configuration options
88
*/
9-
export default defineConfig({
10-
base: "./",
11-
plugins: [react()],
12-
server: {
13-
port: process.env.PORT ? parseInt(process.env.PORT) : 3001,
14-
},
15-
build: {
16-
outDir: "build",
17-
},
18-
}) satisfies UserConfig
9+
export default defineConfig(({ mode }) => {
10+
const env = loadEnv(mode, process.cwd())
11+
12+
const port = env.VITE_PORT ? parseInt(env.VITE_PORT) : 3001
13+
14+
return {
15+
base: "./",
16+
plugins: [react()],
17+
server: {
18+
port,
19+
},
20+
build: {
21+
outDir: "build",
22+
},
23+
} satisfies UserConfig
24+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Run the component's dev server on :3001
22
# (The Streamlit dev server already runs on :3000)
3-
PORT=3001
3+
VITE_PORT=3001
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { defineConfig, UserConfig } from "vite"
1+
import { defineConfig, loadEnv, UserConfig } from "vite"
22
import react from "@vitejs/plugin-react-swc"
33

44
/**
55
* Vite configuration for Streamlit React Component development
66
*
77
* @see https://vitejs.dev/config/ for complete Vite configuration options
88
*/
9-
export default defineConfig({
10-
base: "./",
11-
plugins: [react()],
12-
server: {
13-
port: process.env.PORT ? parseInt(process.env.PORT) : 3001,
14-
},
15-
build: {
16-
outDir: "build",
17-
},
18-
}) satisfies UserConfig
9+
export default defineConfig(({ mode }) => {
10+
const env = loadEnv(mode, process.cwd())
11+
12+
const port = env.VITE_PORT ? parseInt(env.VITE_PORT) : 3001
13+
14+
return {
15+
base: "./",
16+
plugins: [react()],
17+
server: {
18+
port,
19+
},
20+
build: {
21+
outDir: "build",
22+
},
23+
} satisfies UserConfig
24+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Run the component's dev server on :3001
22
# (The Streamlit dev server already runs on :3000)
3-
PORT=3001
3+
VITE_PORT=3001
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { defineConfig, UserConfig } from "vite"
1+
import { defineConfig, loadEnv, UserConfig } from "vite"
22
import react from "@vitejs/plugin-react-swc"
33

44
/**
55
* Vite configuration for Streamlit React Component development
66
*
77
* @see https://vitejs.dev/config/ for complete Vite configuration options
88
*/
9-
export default defineConfig({
10-
base: "./",
11-
plugins: [react()],
12-
server: {
13-
port: process.env.PORT ? parseInt(process.env.PORT) : 3001,
14-
},
15-
build: {
16-
outDir: "build",
17-
},
18-
}) satisfies UserConfig
9+
export default defineConfig(({ mode }) => {
10+
const env = loadEnv(mode, process.cwd())
11+
12+
const port = env.VITE_PORT ? parseInt(env.VITE_PORT) : 3001
13+
14+
return {
15+
base: "./",
16+
plugins: [react()],
17+
server: {
18+
port,
19+
},
20+
build: {
21+
outDir: "build",
22+
},
23+
} satisfies UserConfig
24+
})

0 commit comments

Comments
 (0)