-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
142 lines (141 loc) · 5.39 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
import { viteMockServe } from 'vite-plugin-mock';
// import viteSvgIcons from 'vite-plugin-svg-icons';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { VitePWA } from 'vite-plugin-pwa';
import { defineConfig } from 'vite';
import path from 'path';
import IconsResolver from 'unplugin-icons/resolver';
import Icons from 'unplugin-icons/vite';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
const pathSrc = path.resolve(__dirname, 'src');
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$&*+,:_;<=>?[\]^`{|}\u007F]/g;
const DRIVE_LETTER_REGEX = /^[a-z]:/i;
export default ({ command, mode }) => {
const prodMock = true;
let base = '/vue-admin-template-gen/';
if (mode === 'server') {
base = '/static/vue-admin-template-gen/';
}
return defineConfig({
plugins: [
vue(),
VitePWA({
// registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
manifest: {
name: 'Vue Gen Typescript Admin',
// eslint-disable-next-line camelcase
short_name: 'Vue Ts Admin',
description: 'Description of your app',
// eslint-disable-next-line camelcase
theme_color: '#4DBA87',
icons: [
{
src: 'img/icons/android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'img/icons/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'img/icons/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
}),
vueJsx({
// options are passed on to @vue/babel-plugin-jsx
}),
AutoImport({
imports: ['vue'],
resolvers: [
ElementPlusResolver(),
// Auto import icon components
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
dts: path.resolve(pathSrc, 'auto-imports.d.ts'),
}),
Components({
resolvers: [
// Auto register icon components
// 自动注册图标组件
IconsResolver({
enabledCollections: ['ep'],
}),
// Auto register Element Plus components
// 自动导入 Element Plus 组件
ElementPlusResolver(),
],
dts: path.resolve(pathSrc, 'components.d.ts'),
}),
Icons({
autoInstall: true,
}),
// 添加下面插件
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
symbolId: 'icon-[dir]-[name]',
}),
viteMockServe({
// default
mockPath: 'mock',
localEnabled: command === 'serve',
prodEnabled: command !== 'serve' && prodMock,
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`,
}),
],
base,
server: {
host: true,
open: true,
proxy: {
// https://cn.vitejs.dev/config/#server-proxy
'/dev-api': {
target: 'http://127.0.0.1:5010',
changeOrigin: true,
rewrite: p => p.replace(/^\/dev-api/, ''),
},
},
},
build: {
rollupOptions: {
output: {
// https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts
sanitizeFileName(fileName) {
const match = DRIVE_LETTER_REGEX.exec(fileName);
if (match) {
console.log(fileName);
}
const driveLetter = match ? match[0] : '';
// A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
// Otherwise, avoid them because they can refer to NTFS alternate data streams.
return (
driveLetter + fileName.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, '')
);
},
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
});
};