-
Notifications
You must be signed in to change notification settings - Fork 11
/
vite.base.config.ts
84 lines (80 loc) · 2.41 KB
/
vite.base.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
/// <reference types="vitest" />
import * as path from 'node:path';
import { Plugin, defineConfig } from 'vite';
import { isVue2, isVue3 } from 'vue-demi';
import Unocss from 'unocss/vite';
// @ts-expect-error unocss
import presetUno from '@unocss/preset-uno';
import presetAttributify from '@unocss/preset-attributify';
import DtsPlugin from 'vite-plugin-dts';
const outputName = 'index';
export const getSharedPlugins = (vueVersion: 'v2' | 'v2.7' | 'v3'): Plugin[] => [
Unocss({
presets: [presetAttributify(), presetUno()],
}) as any,
DtsPlugin({
root: '..',
compilerOptions: {
skipLibCheck: true,
},
// only compiler our component source code
include: ['src/**'],
// vue2.6 does not apply to this plugin, ignore the error, 2.6 or handwritten .d.ts is better
skipDiagnostics: vueVersion === 'v2',
noEmitOnError: vueVersion === 'v2',
}),
];
console.log('Vue version:', isVue2 ? 'v2' : 'v3');
// https://vitejs.dev/config/
export const baseBuildConfig = defineConfig({
build: {
outDir: path.resolve(__dirname, `./dist/${isVue2 ? 'v2' : 'v3'}`),
emptyOutDir: false,
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
formats: ['es', 'cjs', 'umd'],
name: 'VueDemiTemplateComponent',
fileName: format => `${outputName}.${format}.js`,
},
rollupOptions: {
external: ['vue',
'@vue/composition-api',
'@vue/composition-api/dist/vue-composition-api.mjs',
],
output: {
globals: {
'vue': 'Vue',
'@vue/composition-api': 'VueCompositionAPI',
'@vue/composition-api/dist/vue-composition-api.mjs':
'VueCompositionAPI',
},
},
},
},
optimizeDeps: {
exclude: ['vue-demi', 'vue', 'vue2', 'vue3'],
},
test: {
globals: true,
environment: 'jsdom',
include: [
'__test__/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
],
alias: {
'@tests/utils': path.resolve(__dirname, `./tests/utils`),
},
setupFiles: [path.resolve(__dirname, 'tests/setup.ts')],
deps: {
inline: ['vue2.7', 'vue2', 'vue-demi', '@vue/test-utils', '@vue/test-utils2'],
},
resolveSnapshotPath: (testPath, snapExtension) => {
return path.join(
path.join(
path.dirname(testPath),
isVue3 ? '__snapshotsV3__' : '__snapshots__',
),
`${path.basename(testPath)}${snapExtension}`,
);
},
},
});