Files
fnx_web/svelte/vite.config.ts

48 lines
1.5 KiB
TypeScript

import { defineConfig } from 'vite';
import { svelte, vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
const production = process.env.NODE_ENV === "production"
console.log("Production mode:", production)
const builddir = "../res/static/svelte"
export default defineConfig({
mode: production ? "production" : "development",
// Chunks are loaded relative to the script which imports them
base: "./",
build: {
outDir: builddir,
emptyOutDir: true,
minify: production,
sourcemap: !production,
// Compile newer syntax down to what browsers from September 2021 support
target: ["chrome94", "edge94", "firefox91", "safari15"],
rollupOptions: {
input: "src/main.ts",
// The entrypoint keeps its name so the HTML template can find it,
// the chunks it imports get a hash in their names
output: { entryFileNames: "main.js" },
},
},
plugins: [
// Svelte can't strip TypeScript enums by itself
svelte({ preprocess: vitePreprocess({ script: true }), emitCss: false }),
// Resolves imports relative to the src directory, like "lib/NovaAPI"
resolve({
browser: true,
exportConditions: ['svelte'],
modulePaths: [process.cwd() + "/src", process.cwd() + "/node_modules"],
extensions: [".svelte", ".mjs", ".js", ".json", ".mts", ".ts"],
}),
// Refresh the browser when the build changes
!production && livereload({
watch: builddir,
port: 5000,
}),
],
});