-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
103 lines (98 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import path from 'node:path'
import process from 'node:process'
import type { UserConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Unocss from 'unocss/vite'
import svgLoader from 'vite-svg-loader'
import dts from 'vite-plugin-dts'
import libCss from 'vite-plugin-libcss'
const libDir = path.resolve(__dirname, 'lib')
const srcDir = path.resolve(__dirname, 'src')
export default defineConfig(async ({ mode }): Promise<UserConfig> => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
const IS_DEMO = process.env.VITE_BUILD_TARGET === 'demo'
return {
resolve: {
alias: {
'@/': `${path.resolve(__dirname, 'playground')}/`,
'~/': `${path.resolve(__dirname, 'src')}/`,
'guodu-tiptap': `${path.resolve(__dirname, 'src')}/index.ts`,
},
},
plugins: [
Vue({
template: {
compilerOptions: {
isCustomElement: (tag) => {
return ['math-field'].includes(tag)
},
},
},
}),
svgLoader(),
Pages({
dirs: ['playground/pages'],
}),
libCss({}),
// https://github.com/antfu/unplugin-auto-import
AutoImport({
imports: [
'vue',
'vue/macros',
'vue-router',
'@vueuse/core',
],
dts: true,
dirs: [
'./playground/composables',
],
vueTemplate: true,
}),
// https://github.com/antfu/vite-plugin-components
Components({
dirs: ['playground/components', 'src/components'],
dts: true,
}),
// https://github.com/antfu/unocss
// see unocss.config.ts for config
Unocss(),
IS_DEMO
? null
: dts({
include: ['src'],
insertTypesEntry: true,
}),
],
build: IS_DEMO
? undefined
: {
outDir: libDir,
minify: 'esbuild',
lib: {
entry: path.resolve(srcDir, 'index.ts'),
name: 'GuoduTiptap',
fileName: 'guodu-tiptap',
},
cssCodeSplit: true,
// https://rollupjs.org/guide/en/#big-list-of-options
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external: ['vue'],
output: {
exports: 'named',
// https://github.com/henriquehbr/svelte-typewriter/issues/21#issuecomment-968835822
// inlineDynamicImports: true,
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
vue: 'vue',
},
},
},
},
publicDir: IS_DEMO ? 'public' : false,
}
})