Skip to content

Commit 1727bcb

Browse files
committed
chore(playground): update vite build to get project name from dsn
1 parent cc213b8 commit 1727bcb

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

packages/playground/admin/vite.config.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@ import { defineConfig } from 'vite'
55
import { resolveConfig } from '../../../build/createViteConfig.js'
66
import { resolve } from 'node:path'
77

8-
export default defineConfig({
9-
base: '/',
10-
plugins: [
11-
react(),
12-
{
13-
name: 'rewrite-middleware',
14-
configureServer(serve) {
15-
serve.middlewares.use((req, res, next) => {
16-
if (req.url === '/app' || req.url?.startsWith('/app/') && !req.url?.match(/\.\w+($|\?)/)) {
17-
req.url = '/app/'
18-
}
19-
next()
20-
})
8+
export default defineConfig(() => {
9+
const dsn = process.argv.find(it => it.includes('://'))
10+
const projectName = dsn ? new URL(dsn).username : null
11+
return ({
12+
define: projectName ? {
13+
'import.meta.env.VITE_CONTEMBER_ADMIN_PROJECT_NAME': JSON.stringify(projectName),
14+
} : {},
15+
base: '/',
16+
plugins: [
17+
react(),
18+
{
19+
name: 'rewrite-middleware',
20+
configureServer(serve) {
21+
serve.middlewares.use((req, res, next) => {
22+
if (req.url === '/app' || req.url?.startsWith('/app/') && !req.url?.match(/\.\w+($|\?)/)) {
23+
req.url = '/app/'
24+
}
25+
next()
26+
})
27+
},
2128
},
22-
},
23-
],
24-
resolve: resolveConfig,
25-
build: {
26-
rollupOptions: {
27-
input: {
28-
root: resolve(__dirname, './index.html'),
29-
app: resolve(__dirname, './app/index.html'),
29+
],
30+
resolve: resolveConfig,
31+
build: {
32+
rollupOptions: {
33+
input: {
34+
root: resolve(__dirname, './index.html'),
35+
app: resolve(__dirname, './app/index.html'),
36+
},
3037
},
3138
},
32-
},
3339

40+
})
3441
})

packages/playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "vite build admin",
88
"contember": "docker-compose run contember-cli",
9-
"deploy": "yarn -- contember deploy playground --admin http://admin-server:4000 --yes",
9+
"deploy": "yarn run build \"$0\" && docker-compose run --no-deps contember-cli deploy \"$@\" --root ",
1010
"start": "vite dev admin --port ${VITE_PORT:-3000} --host 0.0.0.0",
1111
"test": "vitest --root ./ --environment jsdom"
1212
},

0 commit comments

Comments
 (0)