mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
41 lines
1.6 KiB
JavaScript
41 lines
1.6 KiB
JavaScript
import { defineConfig, loadEnv } from 'vite'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
function sandboxOrigin(mode) {
|
|
const envDir = fileURLToPath(new URL('.', import.meta.url))
|
|
const { TREK_CLOUD_SANDBOX_ORIGIN: origin } = loadEnv(mode, envDir, 'TREK_CLOUD_SANDBOX_')
|
|
const url = URL.canParse(origin) ? new URL(origin) : null
|
|
// The host must also support a wildcard certificate for its tenant subdomains.
|
|
const dnsName = /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z][a-z0-9-]*[a-z0-9]$/
|
|
if (
|
|
url?.origin !== origin ||
|
|
url?.protocol !== 'https:' ||
|
|
url.port ||
|
|
!dnsName.test(url.hostname) ||
|
|
url.hostname === 'liketrek.com' ||
|
|
url.hostname === 'www.liketrek.com'
|
|
) {
|
|
throw new Error('TREK_CLOUD_SANDBOX_ORIGIN must be a dedicated sandbox HTTPS origin without a path or port')
|
|
}
|
|
return origin
|
|
}
|
|
|
|
// The address screen the native apps ship (native-shell/). Everything past it
|
|
// is the UI of the server the user picks, so this build stays tiny and apart
|
|
// from the main one: no PWA, no React, only the native strings of each locale.
|
|
export default defineConfig(({ command, mode }) => {
|
|
const sandbox = command === 'build' && mode === 'store-sandbox'
|
|
const output = sandbox ? './native-sandbox-dist' : './native-dist'
|
|
return {
|
|
root: fileURLToPath(new URL('./native-shell', import.meta.url)),
|
|
base: './',
|
|
publicDir: false,
|
|
define: sandbox ? { __TREK_STORE_SANDBOX_ORIGIN__: JSON.stringify(sandboxOrigin(mode)) } : {},
|
|
build: {
|
|
outDir: fileURLToPath(new URL(output, import.meta.url)),
|
|
emptyOutDir: true,
|
|
target: ['es2020', 'safari15', 'chrome100'],
|
|
},
|
|
}
|
|
})
|