-
Notifications
You must be signed in to change notification settings - Fork 7
/
vite.config.js
116 lines (102 loc) · 3.95 KB
/
vite.config.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// import path from 'path';
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, typhonjsRuntime } from '@typhonjs-fvtt/runtime/rollup';
const s_COMPRESS = false; // Set to true to compress the module bundle.
const s_SOURCEMAPS = true; // Generate sourcemaps for the bundle (recommended).
// Set to true to enable linking against the TyphonJS Runtime Library module.
// You must add a Foundry module dependency on the `typhonjs` Foundry package or manually install it in Foundry from:
// https://github.com/typhonjs-fvtt-lib/typhonjs/releases/latest/download/module.json
const s_TYPHONJS_MODULE_LIB = false;
// Used in bundling.
const s_RESOLVE_CONFIG = {
browser: true,
dedupe: ['svelte'],
};
const fvttHandlebarsHML = () => ({
name: 'vite-plugin-fvtt-handlebars-hml',
handleHotUpdate({ file, read, server, modules }) {
if (file.endsWith('.hbs')) {
console.log(file);
read().then((content) =>
server.ws.send({
type: 'custom',
event: 'handlebars-update',
data: {
file: 'systems/zweihander/src/templates/' + file.split('/templates/')[1],
content,
},
})
);
return [];
}
return modules;
},
});
export default () => {
/** @type {import('vite').UserConfig} */
return {
root: 'src/', // Source location / esbuild root.
base: '/systems/zweihander/', // Base module path that 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: s_COMPRESS, sourceMap: s_SOURCEMAPS }),
},
// 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 `lang` will pull the language resources from the main Foundry / 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: 40001,
open: false,
proxy: {
'^(/systems/zweihander/(lang|packs|assets|fonts|tinymce))': 'http://localhost:40000',
'^(?!/systems/zweihander/)': 'http://localhost:40000',
'/socket.io': { target: 'ws://localhost:40000', ws: true },
},
},
build: {
outDir: __dirname,
emptyOutDir: false,
sourcemap: s_SOURCEMAPS,
brotliSize: true,
minify: s_COMPRESS ? 'terser' : false,
target: ['es2022', 'chrome100'],
terserOptions: s_COMPRESS ? { ...terserConfig(), ecma: 2022 } : void 0,
lib: {
entry: './index.js',
formats: ['es'],
fileName: 'index',
},
},
plugins: [
fvttHandlebarsHML(),
svelte({
preprocess: preprocess(),
onwarn: (warning, handler) => {
// Suppress `a11y-missing-attribute` for missing href in <a> links.
// Foundry doesn't follow accessibility rules.
if (warning.message.includes(`<a> element should have an href attribute`)) {
return;
}
// Let Rollup handle all other warnings normally.
handler(warning);
},
}),
resolve(s_RESOLVE_CONFIG), // Necessary when bundling npm-linked packages.
// When s_TYPHONJS_MODULE_LIB is true transpile against the Foundry module version of TRL.
s_TYPHONJS_MODULE_LIB && typhonjsRuntime(),
],
};
};