forked from arcanistzed/mcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
100 lines (88 loc) · 3 KB
/
vite.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import resolve from "@rollup/plugin-node-resolve"; // This resolves NPM modules from node_modules
import preprocess from "svelte-preprocess";
import { postcssConfig, terserConfig } from "@typhonjs-fvtt/runtime/rollup";
const MODULE_ID = "mcc";
export default defineConfig(({ command }) => {
const PRODUCTION = command === "build";
const COMPRESS = PRODUCTION; // Compress the module bundle in production mode
const SOURCEMAPS = PRODUCTION; // Generate sourcemaps for the bundle in production mode
return {
root: "src/", // Source location (esbuild root)
base: `/modules/${MODULE_ID}/`, // Base module path for port 30001 (served dev directory)
publicDir: false, // No public resources to copy
cacheDir: "../.vite-cache", // Relative from root directory
resolve: { conditions: ["import", "browser"] },
esbuild: {
target: ["es2022", "chrome100"],
keepNames: true, // Note: doesn't seem to work
},
css: {
// Creates a standard configuration for PostCSS with autoprefixer & postcss-preset-env
postcss: postcssConfig({
compress: COMPRESS,
sourceMap: SOURCEMAPS,
extract: "style.css",
}),
},
// About server options:
// - Set to `open` to boolean `false` to not open a browser window automatically. This is useful if you set up a debugger instance in your IDE and launch it with the URL: 'http://localhost:30001/game'.
// - The top proxy entry for `languages` will pull the language resources from the main FVTT (port 30000) server. This is necessary to reference the dev resources as the root is `/src` and there is no public / static resources served.
server: {
port: 30001,
open: "/game",
proxy: {
[`^(/modules/${MODULE_ID}/languages)`]:
"http://localhost:30000",
[`^(?!/modules/${MODULE_ID}/)`]: "http://localhost:30000",
"/socket.io": { target: "ws://localhost:30000", ws: true },
},
hmr: {
overlay: false,
},
},
build: {
outDir: __dirname,
emptyOutDir: false,
sourcemap: SOURCEMAPS,
brotliSize: true,
minify: COMPRESS ? "terser" : false,
target: ["es2022", "chrome100"],
terserOptions: COMPRESS
? { ...terserConfig(), ecma: 2022 }
: void 0,
lib: {
entry: "./index.js",
formats: ["es"],
fileName: "index",
},
},
plugins: [
svelte({
preprocess: preprocess(),
onwarn: (warning, handler) => {
// Suppress `a11y-missing-attribute` for missing href in <a> links
// Suppress `a11y-label-has-associated-control` for detached <label> and control
if (
warning.message.includes(
"<a> element should have an href attribute"
) ||
warning.message.includes(
"A form label must be associated with a control"
)
) {
return;
}
// Let Rollup handle all other warnings normally
handler && handler(warning);
},
}),
// Necessary when bundling npm-linked packages
resolve({
browser: true,
dedupe: ["svelte"],
}),
],
};
});