-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
83 lines (83 loc) · 2.29 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
/*
* @description:
* @author: xiangrong.liu
* @Date: 2021-12-09 14:56:24
* @LastEditors: xiangrong.liu
* @LastEditTime: 2022-02-26 07:27:41
*/
import { UserConfigExport, ConfigEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import { viteVConsole } from 'vite-plugin-vconsole';
import { resolve } from 'path';
import eslintPlugin from 'vite-plugin-eslint';
import legacy from '@vitejs/plugin-legacy';
import devServer from './build/devServer';
import legacyConf from './build/legacyConf';
import styleImport from 'vite-plugin-style-import';
import { visualizer } from 'rollup-plugin-visualizer';
export default ({ mode }: ConfigEnv): UserConfigExport => {
console.log(resolve(__dirname, './src/main.ts'), mode);
return {
resolve: {
alias: [{ find: '@', replacement: resolve(__dirname, './src') }],
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "@/styles/reset.scss";@import "@/styles/variables.scss";`
}
}
},
// base属性相当于webpack的publicPath属性。配置cdn的时候需要用到
base: mode !== 'dev' ? '/hyth5/' : '/',
plugins: [
vue(),
styleImport({
libs: [
{
libraryName: 'vant',
esModule: true,
resolveStyle: (name) => `vant/es/${name}/style`
}
]
}),
viteVConsole({
entry: resolve(__dirname, './src/main.ts').replace(/\\/g, '/'), // entry file
localEnabled: mode !== 'prod', // dev environment
enabled: mode !== 'prod', // build production
config: {
// vconsole options
maxLogNumber: 1000,
theme: 'light'
}
}),
// eslintPlugin({ cache: false }),
legacy({
targets: ['defaults', 'not IE 11']
}),
visualizer()
// viteExternalsPlugin({
// echarts: 'echarts'
// })
],
// optimizeDeps: {
// include: ['vant/es']
// },
server: devServer,
build: {
target: 'es2015',
outDir: './dist/',
cssCodeSplit: true,
// sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
echarts: ['echarts']
}
}
}
// minify: false
}
};
};