forked from kakajun/vue3-sketch-ruler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
69 lines (65 loc) · 1.5 KB
/
vite.config.js
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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { existsSync, readdirSync, lstatSync, rmdirSync, unlinkSync } from 'fs'
import { resolve } from 'path'
import dts from 'vite-plugin-dts'
const pkg = require('./package.json')
emptyDir(resolve(__dirname, 'types'))
const banner = `/*!
* ${pkg.name} v${pkg.version}
* ${new Date().getFullYear()}年${new Date().getMonth() + 1}月${new Date()}
* 制作
*/`
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
dts({
outputDir: 'types',
staticImport: true,
insertTypesEntry: true,
logDiagnostics: true
})
],
optimizeDeps: {
exclude: ['vue-demi']
},
resolve: {
alias: {
'@': resolve(__dirname)
}
},
build: {
outDir: 'lib/v3',
// minify: true, // 不压缩代码,方便开发调试
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'SketchRuler',
fileName: 'index',
formats: ['es', 'cjs', 'umd']
},
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external: ['vue', 'vue-demi'],
output: {
banner,
exports: 'auto'
}
}
}
})
function emptyDir(dir) {
if (!existsSync(dir)) {
return
}
for (const file of readdirSync(dir)) {
const abs = resolve(dir, file)
// baseline is Node 12 so can't use rmSync
if (lstatSync(abs).isDirectory()) {
emptyDir(abs)
rmdirSync(abs)
} else {
unlinkSync(abs)
}
}
}