This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
98 lines (95 loc) · 3.33 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
/// <reference types="@histoire/plugin-vue/components" />
import path from 'path'
import { defineConfig } from 'vite'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import svgLoader from 'vite-svg-loader'
import Vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
// Overwrite `apply` of `plugin-vue` so that it
// only applies on `test` mode. Otherwise `npm run build` will fail
// with:
// ```sh
// ERROR Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).
// ```
// Read for apply: https://vitejs.dev/guide/api-plugin.html#conditional-application
const pluginVue = Vue()
pluginVue.apply = (_, { mode }: { mode: string }) => {
// apply only on `test` so that `vitest` understands vue. Else `vitest` will say:
// ```sh
// Error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
// ```
// guess: because nuxt already applies its own template transformation
return mode === 'test'
}
const include = [/\.vue$/, /\.vue\?vue/, /\.stories\.ts$/, /\.[tj]s$/]
export default defineConfig({
resolve: {
alias: {
'~': path.resolve(__dirname),
},
},
plugins: [
// Make composable, components and ant-design imports work inside `vitest`, `storybook`
pluginVue,
Components({
dirs: ['~/components'],
directoryAsNamespace: true,
resolvers: [AntDesignVueResolver()],
include,
}),
AutoImport({
include,
imports: ['vue'],
dirs: ['~/composables'],
vueTemplate: true,
}),
svgLoader(),
],
// Make `ant-design-vue` work as at the moment there's still problems with Vite SSR + ant design,
// see [this for source of fix](https://github.com/vueComponent/ant-design-vue/discussions/5210)
// and [reported but unresolved here](https://github.com/vueComponent/ant-design-vue/issues/3997).
// For latest occurence + resolution see here: https://github.com/nuxt/framework/issues/6941#issuecomment-1229739856
ssr: {
noExternal: ['moment', 'compute-scroll-into-view', 'ant-design-vue', '@ant-design/icons-vue', 'dayjs'],
},
// vitest configuration
// see https://vitest.dev/config/
test: {
threads: false,
environment: 'jsdom',
coverage: {
enabled: false,
lines: 90,
functions: 90,
branches: 90,
// We want to catch all js/ts/... files, not only the ones imported in some tests
// see https://github.com/bcoe/c8#checking-for-full-source-coverage-using---all
all: true,
include: [
// Nuxt 3 framework folders and files sources from directory structure here: https://v3.nuxtjs.org/guide/concepts/introduction
'assets',
'components',
'composables',
'layouts',
'middleware',
'pages',
'public',
'server',
'app.vue',
],
exclude: ['**/*.story.vue', '**/*.test.ts', 'app.vue', 'pages/**/*.vue', 'server/database/index.ts'],
},
deps: {
// `ant-design-vue` breaks vitest unless we inline it here,
// because the `ant-design-vue` library does not properly
// define its JS-style (CommonJS es ESM)
inline: [
'ant-design-vue',
],
},
setupFiles: [
'./tests/setupTestUtils.ts',
],
},
})