-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.lib.ts
117 lines (113 loc) · 3.17 KB
/
vite.lib.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
import path, { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import dts from 'vite-plugin-dts'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig(() => {
const common = {
plugins: [
vue(),
vueJsx(),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
],
imports: ['vue'],
dirs: [],
resolvers: [ElementPlusResolver()],
}),
dts({
entryRoot: './packages',
outDir: [resolve(__dirname, './es'), resolve(__dirname, './lib')],
//指定使用的tsconfig.json为我们整个项目根目录下掉,如果不配置,你也可以在components下新建tsconfig.json
tsconfigPath: './tsconfig.json',
copyDtsFiles: true,
include: [
'packages',
'global.d.ts',
'auto-imports.d.ts',
'components.d.ts',
],
}),
Components({
globs: ['**/src/*.{tsx|vue}'],
include: [/\.(vue|tsx)$/, /\.vue\?vue/],
resolvers: [
ElementPlusResolver({
importStyle: 'sass',
}),
],
}),
(function injectCss() {
return {
name: 'injectCss',
transform(code: string, id: string) {
if (id.includes('packages/index.ts')) {
let scssUrl = ''
scssUrl += `import './style.css'\n`
code = scssUrl + code
}
return { code, map: null }
},
}
})(),
],
resolve: {
alias: {
'~': path.resolve('./packages'),
'#': path.resolve('./typings'),
},
},
// 控制台打印
// logLevel: "silent",
}
return {
...common,
build: {
target: 'modules',
//打包文件目录
// sourcemap: 'hidden',
//压缩
minify: true,
//css分离
// cssCodeSplit: true,
rollupOptions: {
//忽略打包vue文件
external: ['vue', './style.css', /^(@e|e)lement-plus*/],
input: ['./packages/index.ts'],
output: [
{
format: 'es' as const,
//不用打包成.es.js,这里我们想把它打包成.js
entryFileNames: '[name].mjs',
//让打包目录和我们目录对应
preserveModules: true,
exports: 'named' as const,
//配置打包根目录
dir: resolve(__dirname, './es'),
compact: true,
sourcemap: true,
},
{
format: 'cjs' as const,
//不用打包成.cjs
entryFileNames: '[name].js',
//让打包目录和我们目录对应
preserveModules: true,
exports: 'named' as const,
//配置打包根目录
dir: resolve(__dirname, './lib'),
},
],
},
lib: {
entry: './packages/index.ts',
name: 'el-plus-powerful-form',
},
},
}
})