Amp-Thread-ID: https://ampcode.com/threads/T-019f8aec-e13a-7495-a56f-89bcb9e9fbc1 Co-authored-by: Amp <amp@ampcode.com>
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { defineConfig } from "vite";
|
|
import { ViteRsw } from "vite-plugin-rsw";
|
|
import wasm from "vite-plugin-wasm";
|
|
import copy from "rollup-plugin-copy";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const portalHost = process.env.PUBLIC_URL
|
|
? new URL(process.env.PUBLIC_URL).hostname
|
|
: undefined;
|
|
const serverPort = Number(process.env.PORT) || 8080;
|
|
|
|
export default defineConfig({
|
|
build: {
|
|
rollupOptions: {
|
|
input: {
|
|
app: "static/index.html",
|
|
},
|
|
},
|
|
// Relative to 'root'.
|
|
outDir: "../dist",
|
|
copyPublicDir: true,
|
|
},
|
|
// For getting out of index.html from dist/static directory.
|
|
root: "static",
|
|
publicDir: ".",
|
|
worker: {
|
|
format: "es",
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
pkg: path.resolve(__dirname, "level-editor/pkg"),
|
|
},
|
|
},
|
|
plugins: [
|
|
copy({
|
|
targets: [
|
|
{ src: "level-editor/pkg/*", dest: "static/level-editor/pkg" },
|
|
],
|
|
hook: "buildStart",
|
|
}),
|
|
ViteRsw(),
|
|
// Makes us be able to use top level await for wasm.
|
|
// Otherwise, we can restrict build.target to 'es2022', which allows top level await.
|
|
wasm(),
|
|
],
|
|
server: {
|
|
host: process.env.PORT ? "0.0.0.0" : undefined,
|
|
port: serverPort,
|
|
strictPort: true,
|
|
allowedHosts: portalHost ? [portalHost, ".e2b.app"] : [],
|
|
headers: {
|
|
"Cross-Origin-Embedder-Policy": "require-corp",
|
|
"Cross-Origin-Opener-Policy": "same-origin",
|
|
},
|
|
fs: {
|
|
strict: false,
|
|
},
|
|
},
|
|
preview: {
|
|
port: 8080,
|
|
allowedHosts: portalHost ? [portalHost, ".e2b.app"] : [],
|
|
headers: {
|
|
"Cross-Origin-Embedder-Policy": "require-corp",
|
|
"Cross-Origin-Opener-Policy": "same-origin",
|
|
},
|
|
},
|
|
});
|