-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvite.config.ts
172 lines (168 loc) · 6.28 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import vue from '@vitejs/plugin-vue'
import dts from 'vite-plugin-dts'
import { resolve } from 'path'
import { copyFileSync } from 'fs'
import { name, version } from './packages/components/package.json'
import type { UserConfigExport } from 'vite'
export default (): UserConfigExport => {
/**
* @see define https://cn.vitejs.dev/config/shared-options.html#define
* @description 修改默认配置
*/
return {
define: {
isDev: process.env.NODE_ENV !== 'production'
},
/**
* 插件配置
*
* @see plugins https://cn.vitejs.dev/config/shared-options.html#plugins
* @description 插件配置 插件是一个函数或者是一个包含 { apply } 的对象。
*/
plugins: [
/**
* @see vite-plugin-vue https://github.com/vitejs/vite-plugin-vue
* @description vue 插件
*/
vue(),
/**
* @see vite-plugin-dts https://github.com/qmhc/vite-plugin-dts
* @skipDiagnostics 是否跳过类型诊断
* @staticImport 是否将动态引入转换为静态
* @outputDir 可以指定一个数组来输出到多个目录中
* @insertTypesEntry 是否生成类型声明入口
* @cleanVueFileName 是否将 '.vue.d.ts' 文件名转换为 '.d.ts'
* @copyDtsFiles 是否将源码里的 .d.ts 文件复制到 outputDir
* @include 手动设置包含路径的 glob
* @afterBuild 构建后回调钩子
* @description vite 插件,用于打包类型声明文件
*/
dts({
skipDiagnostics: true,
// todo 如果丢失了声明文件 打开下面两行
// skipDiagnostics: false,
// afterDiagnostic: diagnostics => {
// console.log(diagnostics)
// },
staticImport: true,
outputDir: ['./dist/lib', './dist/es'],
insertTypesEntry: true,
cleanVueFileName: true,
copyDtsFiles: true,
include: ['./packages/components'],
afterBuild: (): void => {
move()
}
})
],
/**
* @see 构建选项 https://cn.vitejs.dev/config/build-options.html
* @target 这是指 支持原生 ES 模块、原生 ESM 动态导入
* @minify 压缩代码
* @chunkSizeWarningLimit 打包的组件超过 2kb 警告提示
* @reportCompressedSize 启用 gzip 压缩大小报告
* @emptyOutDir 是否清空输出目录
* @outDir 指定输出路径
* @lib.name 包名
* @lib.entry 打包入口
* @description 构建配置项
*/
build: {
target: 'modules',
minify: true,
chunkSizeWarningLimit: 2,
reportCompressedSize: true,
emptyOutDir: false,
outDir: resolve(__dirname, './dist'),
lib: {
name: 'dkPlus',
entry: resolve(__dirname, 'packages/components/index.ts')
},
rollupOptions: {
/**
* @see external https://rollupjs.org/guide/en/#external
* @name 包名字
* @format 包的格式
* @see output.format https://rollupjs.org/guide/en/#outputformat
* @exports 指定导出的方式
* @see output.exports https://rollupjs.org/guide/en/#outputexports
* @sourcemap 是否生成 sourcemap
* @see output.outputsourcemap https://rollupjs.org/guide/en/#outputsourcemap
* @dir 指定输出目录
* @see output.outputdir https://rollupjs.org/guide/en/#outputdir
* @entryFileNames 指定入口文件名
* @see output.outputentryfilenames https://rollupjs.org/guide/en/#outputentryfilenames
* @chunkFileNames 指定块文件名
* @see output.outputchunkfilenames https://rollupjs.org/guide/en/#outputchunkfilenames
* @assetFileNames 指定资源文件名
* @see output.outputassetfilenames https://rollupjs.org/guide/en/#outputassetfilenames
* @manualChunks 手动指定块
* @see output.outputmanualchunks https://rollupjs.org/guide/en/#outputmanualchunks
* @inlineDynamicImports 是否内联动态导入
* @see output.outputinlinedynamicimports https://rollupjs.org/guide/en/#outputinlinedynamicimports
* @globals 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
* @namespaceToStringTag 为命名空间提供 toStringTag
* @see output.outputnamespacetostringtag https://rollupjs.org/guide/en/#outputnamespacetostringtag
* @description 外部化处理那些你不想打包进库的依赖
*/
external: ['vue'],
output: [
{
name: 'dkPlus',
format: 'umd',
exports: 'named',
sourcemap: false,
dir: 'dist/dkPlus',
entryFileNames: 'index.umd.js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]',
manualChunks: undefined,
inlineDynamicImports: false,
globals: {
vue: 'Vue'
},
namespaceToStringTag: true
},
{
format: 'es',
exports: 'named',
dir: 'dist/es',
sourcemap: false,
entryFileNames: 'index.js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]',
inlineDynamicImports: false,
manualChunks: undefined,
preserveModules: true,
namespaceToStringTag: true
},
{
format: 'cjs',
exports: 'named',
dir: 'dist/lib',
sourcemap: false,
entryFileNames: 'index.js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]',
inlineDynamicImports: false,
manualChunks: undefined,
preserveModules: true,
namespaceToStringTag: true
}
]
}
}
}
}
/** 打包结束之后将一些静态文件进行移入 */
const move = (): void => {
const files = [
{ input: './README.md', outDir: 'dist/README.md' },
{ input: './packages/components/package.json', outDir: 'dist/package.json' },
{ input: './LICENSE', outDir: 'dist/LICENSE' }
] as const
files.forEach((item): void => {
copyFileSync(item.input, item.outDir) // 同步拷贝文件
})
console.warn('\n' + `${name} ${version} 版本打包成功🎇🎇🎇🎇🎇🎇🎇🎇🎇🎇🎇` + '\n')
}