-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
57 lines (54 loc) · 1.63 KB
/
vite.config.ts
File metadata and controls
57 lines (54 loc) · 1.63 KB
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
/* eslint-disable node/prefer-global/process */
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { defineConfig } from 'vite';
const __dirname = dirname(fileURLToPath(import.meta.url));
const componentName = process.env.COMPONENT_NAME;
const componentPath = process.env.COMPONENT_PATH || componentName;
// https://vite.dev/config/
export default defineConfig(() => {
return {
plugins: [vue(), vueJsx()],
server: {
// 将 dist 目录代理到 /dist 路径,方便开发时访问构建产物
fs: {
strict: false,
allow: ['..'],
},
},
build: componentName
? ({
lib: {
entry: resolve(__dirname, `./src/templates/${componentPath}/index.vue`),
formats: ['iife'],
name: componentName,
fileName(_format) {
return 'index.js';
},
},
rollupOptions: {
external: ['vue'],
output: {
globals: {
vue: 'Vue',
},
assetFileNames: (assetInfo) => {
if (assetInfo.name?.endsWith('.css')) {
return 'index.css';
}
return assetInfo.name || 'asset.[ext]';
},
format: 'iife',
exports: 'default',
},
},
emptyOutDir: false, // Don't empty dist on each build
outDir: `dist/templates/${componentPath}`,
})
: {
emptyOutDir: false,
},
};
});