-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
73 lines (69 loc) · 2.09 KB
/
vite.config.ts
File metadata and controls
73 lines (69 loc) · 2.09 KB
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
/// <reference types="vitest" />
import { resolve } from 'node:path';
import { defineConfig, type UserConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import legacy from '@vitejs/plugin-legacy';
import ViteYaml from '@modyfi/vite-plugin-yaml';
import { ViteMinifyPlugin } from 'vite-plugin-minify';
import distDirs from './dist-dirs.json' with { type: 'json' };
import { getAliases, getClientEnvironmentVariables, getSelfDirectoryAbsolutePath } from './vite-config-helper';
const WEB_DIRECTORY = resolve(getSelfDirectoryAbsolutePath(), 'src/presentation');
const TEST_INITIALIZATION_FILE = resolve(getSelfDirectoryAbsolutePath(), 'tests/shared/bootstrap/setup.ts');
export function createVueConfig(options?: {
readonly supportLegacyBrowsers: boolean,
}): UserConfig {
return {
root: WEB_DIRECTORY,
build: {
outDir: resolve(getSelfDirectoryAbsolutePath(), distDirs.web),
},
plugins: [
vue(),
ViteYaml(),
...[options?.supportLegacyBrowsers ? legacy() : undefined],
ViteMinifyPlugin(getStaticHtmlMinificationOptions()), // Minifies index.html
],
esbuild: {
supported: {
'top-level-await': true, // Exclude browsers not supporting top-level-await
},
},
define: {
...getClientEnvironmentVariables(),
},
resolve: {
alias: {
...getAliases(),
},
},
server: {
port: 3169,
},
test: {
globals: true,
environment: 'jsdom',
alias: {
...getAliases(),
},
setupFiles: [
TEST_INITIALIZATION_FILE,
],
},
};
}
export default defineConfig(createVueConfig({
supportLegacyBrowsers: true,
}));
function getStaticHtmlMinificationOptions(): Parameters<typeof ViteMinifyPlugin>[0] {
return {
/* Options: https://www.npmjs.com/package/html-minifier-terser */
minifyCSS: true,
minifyJS: true,
removeComments: true,
noNewlinesBeforeTagClose: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
customAttrCollapse: /.*/, // Strip newlines from all attributes
collapseWhitespace: true,
};
}