forked from PanJiaChen/vue-element-admin
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvite.config.js
146 lines (143 loc) · 4.24 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
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
import path from 'path-browserify'
// import fs from 'fs'
import { defineConfig, loadEnv } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import { createHtmlPlugin } from 'vite-plugin-html'
import styleImport from 'vite-plugin-style-import'
// import replace from '@rollup/plugin-replace'
import eslintPlugin from 'vite-plugin-eslint'
// 雪碧图插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd())
return defineConfig({
define: {
'process.env': { ...env }
},
plugins: [
createVuePlugin({
jsx: true
}),
eslintPlugin(),
createHtmlPlugin({
minify: true,
inject: {
data: {
title: 'vue Element Admin',
cdn: {
css: [],
js: [
// '//cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js',
// '//cdn.jsdelivr.net/npm/vue-router@3.5.1/dist/vue-router.min.js',
// '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
// '//cdn.jsdelivr.net/npm/axios@0.21.1/dist/axios.min.js',
]
}
}
}
}),
styleImport({
libs: [
{
libraryName: 'element-ui',
// styleLibraryName: 'theme-chalk',
esModule: true,
resolveStyle: (name) => {
return `theme-chalk/${name}.css`
}
}
]
}),
// 雪碧图
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(__dirname, './src/icons/svg')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]',
/**
* 自定义插入位置
* @default: body-last
*/
inject: 'body-last' | 'body-first',
/**
* custom dom id
* @default: __svg__icons__dom__
*/
customDomId: '__svg__icons__dom__'
})
],
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
alias: [
{
find: /@\/.+/,
replacement: (val) => {
return val.replace(/^@/, path.resolve(__dirname, '/src/'))
}
},
{
// this is required for the SCSS modules
find: /^~(.*)$/,
replacement: '$1'
}
// {
// find: '@',
// replacement: path.resolve(__dirname, 'src'),
// },
// {
// 'venn.js': 'venn.js/build/venn.js',
// },
]
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
// additionalData: `@import "./node_modules/ant-design-vue/lib/style/index.less";
// @import "./node_modules/ant-design-vue/es/style/themes/default.less";`,
// additionalData: `@import "${path.resolve(__dirname, 'src/assets/style/global.less')}";`,
modifyVars: {}
}
// scss: {
// additionalData: `@import "${path.resolve(__dirname, 'src/styles/element-variables.scss')}";
// @import "${path.resolve(__dirname, 'src/styles/index.scss')}";`
// }
}
},
build: {
target: 'es2015',
cssTarget: 'chrome80',
brotliSize: false,
chunkSizeWarningLimit: 2000,
commonjsOptions: {
// 改为 ture 后就会转化 require 语法
transformMixedEsModules: true
}
// rollupOptions: {
// // 确保外部化处理那些你不想打包进库的依赖
// external: ['vue', 'vue-router', 'vuex', 'axios', 'xlsx'],
// output: {
// // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
// globals: {
// vue: 'Vue',
// 'vue-router': 'VueRouter',
// vuex: 'Vuex',
// axios: 'axios',
// xlsx: 'XLSX'
// }
// }
// }
},
server: {
port: 9527
// proxy: {
// '/api': {
// target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
// changeOrigin: true,
// ws: false,
// rewrite: (path) => path.replace(/^\/api/, ''),
// }
// },
}
})
}