-
Notifications
You must be signed in to change notification settings - Fork 17
/
vite.config.ts
49 lines (47 loc) · 1.9 KB
/
vite.config.ts
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
/// <reference types="vitest" />
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig, loadEnv, type UserConfig } from 'vite';
import { imagetools } from '@zerodevx/svelte-img/vite';
import { createAvailableLocales } from './plugins/available-locales';
import { customSvgLoader } from './plugins/svg-loader';
import mkcert from 'vite-plugin-mkcert';
import envIsTrue from './src/lib/util/env-is-true';
/* eslint-env node */
export default defineConfig(({ command, mode }): UserConfig => {
// Careful: this will not include the "always available" env vars (https://vitejs.dev/guide/env-and-mode.html#env-variables)
// like MODE and DEV; those are available from the UserConfig somehow.
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
const isProductionBuild = command === 'build' && (mode === 'production' || mode === 'staging');
const useHTTPS = envIsTrue(process.env.VITE_USE_DEV_HTTPS) ?? false;
return {
build: {
minify: isProductionBuild ? 'esbuild' : false
},
plugins: [
createAvailableLocales(),
customSvgLoader({ removeSVGTagAttrs: false }),
sveltekit(),
imagetools(),
...(useHTTPS
? [
mkcert({
// Edit your hostfile to map wtmg.dev to 127.0.0.1
// We are not using .local here, request that domain may attempt a multicast
// https://en.wikipedia.org/wiki/.local and take long to resolve.
hosts: ['localhost', '127.0.0.1', 'wtmg.dev']
})
]
: [])
],
ssr: {
// https://vitejs.dev/guide/ssr.html#ssr-externals
// https://github.com/sveltekit-i18n/lib/issues/82
noExternal: ['@sveltekit-i18n/*', 'intl-messageformat', '@formatjs/*']
},
test: {
// Modified from
// https://vitest.dev/config/#include
include: ['tests/unit/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
}
};
});