-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
86 lines (78 loc) · 2.88 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
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
import { sveltekit } from '@sveltejs/kit/vite';
import { loadEnv } from 'vite';
import { defineConfig, type ViteUserConfig } from 'vitest/config';
import type { PluginOption, UserConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
// import basicSsl from '@vitejs/plugin-basic-ssl';
import replace from '@rollup/plugin-replace';
import backloopHttpsOptions from 'backloop.dev';
import Icons from 'unplugin-icons/vite';
import { FileSystemIconLoader } from 'unplugin-icons/loaders';
import { SvelteKitPWA } from '@vite-pwa/sveltekit';
import { pwaConfigurationFnc } from './pwa-configuration.js';
import assets from './assets.js';
export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, process.cwd());
const { pwaConfiguration, replaceOptions } = await pwaConfigurationFnc(env);
const PROD_DEBUG = env.VITE_PROD_DEBUG?.toLowerCase() === 'true';
const plugins = [
// see below: basicSsl(),
sveltekit(),
SvelteKitPWA(pwaConfiguration),
Icons({
// experimental
autoInstall: true,
compiler: 'svelte',
customCollections: {
// Add your custom collection here
images: FileSystemIconLoader(
'./src/lib/images',
(svg) => svg // No processing
// To do any processing: (svg) => svg.replace(/^<svg /, '<svg fill="currentColor" ')
)
}
}),
replace(replaceOptions),
// copy is needed for vite to work in dev (especially under "tauri:dev")
// All copy commands are duplicated in package.json:scripts.svelte:prebuild, for build to work correctly.
viteStaticCopy({
targets: assets
})
] as PluginOption[];
// Playwright does not handle https, see https://github.com/microsoft/playwright/issues/16460
// if (!process.env.NO_HTTPS) plugins.unshift([basicSsl()]);
// Some typing gymnasics to allow 'test' property in ViteConfig, and not fall into PluginOptions type difference:
const config: Omit<ViteUserConfig, 'plugins'> & UserConfig = {
optimizeDeps: {
include: [
'@ionic/pwa-elements/loader/index.cjs.js',
'node_modules/@ionic/pwa-elements/loader/index.cjs.js'
]
},
logLevel: 'info',
build: {
minify: !PROD_DEBUG,
sourcemap: PROD_DEBUG
},
define: {
__DATE__: JSON.stringify(new Date().toISOString()),
__RELOAD_SW__: JSON.stringify(false),
__UPDATE_CHECK_PERIOD_MS__: JSON.stringify(20000) // in milli-seconds, 20s for testing purposes
},
plugins,
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
server: process.env.NO_HTTPS
? {}
: {
// Use valid HTTPS certs for localhost
port: 4443,
// port: 3000,
host: 'total-app.backloop.dev',
https: backloopHttpsOptions,
proxy: {} // Fixes https://github.com/sveltejs/svelte/issues/12398
}
};
return config as ViteUserConfig;
});