-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
144 lines (139 loc) · 3.83 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { fileURLToPath } from 'node:url';
import process from 'node:process';
import { defineConfig, type PluginOption, type UserConfig } from 'vite';
import _ from 'lodash';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as vitest from 'vitest';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import autoImport from 'unplugin-auto-import/vite';
import Icons from 'unplugin-icons/vite';
import { FileSystemIconLoader } from 'unplugin-icons/loaders';
import inspect from 'vite-plugin-inspect';
import inspector from 'vite-plugin-vue-inspector';
import markdownRawPlugin from 'vite-raw-plugin';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import postcssConfig from './postcss.config';
export default defineConfig(async ({ command }) => {
const vitePlugins = [
vue(),
vueJsx(),
// https://github.com/antfu/unplugin-auto-import
autoImport({
imports: [
'vue',
'vue-router',
'vue-i18n',
'vue/macros',
'vuex',
'vitest', // see: https://vitest.dev/config/#globals
'@vueuse/core',
{
'@/hooks/useApi': ['useApi'],
},
],
dts: 'src/types/auto-imports.d.ts',
dirs: ['src/stores'],
vueTemplate: true,
// Generate corresponding .eslintrc-auto-import.json file.
// eslint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals
eslintrc: {
enabled: true,
filepath: './.eslintrc-auto-import.json',
globalsPropValue: true,
},
}),
Icons({
compiler: 'vue3',
customCollections: {
'ccu-disaster-icons': FileSystemIconLoader('src/assets/disaster_icons'),
},
}),
// https://github.com/antfu/vite-plugin-inspect
inspect(),
// https://github.com/webfansplz/vite-plugin-vue-inspector
inspector(),
markdownRawPlugin({
fileRegex: /\.svgr$/,
}),
] as PluginOption[];
const configs: Array<Partial<UserConfig>> = [];
configs.push({
optimizeDeps: {
include: ['tailwind.config'],
},
resolve: {
alias: {
'@': fileURLToPath(new URL('src', import.meta.url)),
'tailwind.config': fileURLToPath(
new URL('tailwind.config.cjs', import.meta.url),
),
},
},
css: {
postcss: {
...postcssConfig,
},
},
build: {
rollupOptions: {
output: {
manualChunks: {
// todo: do not statically import downloads into asset builder
'group-downloads': [
'./src/pages/Downloads.vue',
'./src/components/admin/incidents/IncidentAssetBuilder.vue',
],
},
},
},
},
});
if (command === 'build') {
vitePlugins.push(
sentryVitePlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: 'crisis-cleanup',
project: 'crisiscleanup-4-web',
}),
);
configs.push({
esbuild: {
treeShaking: true,
},
build: {
sourcemap: true,
},
});
}
// Vitest config
configs.push(
{
test: {
include: ['test/**/*.test.ts', 'test/**/*.spec.ts'],
exclude: ['test/e2e/**/*'],
setupFiles: ['./test/setupTests.ts', 'fake-indexeddb/auto'],
globals: true,
environment: 'happy-dom',
deps: {
optimizer: {
web: {
include: ['@vue', '@vueuse'],
},
},
},
coverage: {
provider: 'v8',
include: ['src/**'],
exclude: ['src/external/**', 'src/assets/vendor/js/**'],
reporter: ['text', 'json', 'html'],
},
globalSetup: './test/globalSetup.ts',
},
},
{
plugins: vitePlugins,
},
);
return _.merge({}, ...configs) as UserConfig;
});