forked from JoeshuTT/v-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
105 lines (100 loc) · 2.75 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
import { fileURLToPath, URL } from 'node:url';
import type { UserConfig, ConfigEnv } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import dayjs from 'dayjs';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import legacy from '@vitejs/plugin-legacy';
import AutoComponents from 'unplugin-vue-components/vite';
import { createHtmlPlugin } from 'vite-plugin-html';
import pkg from './package.json';
/** 工作目录 */
const root: string = process.cwd();
/** 静态资源目录 */
const assetsDir = 'assets';
/** 项目信息 */
const { name, version, engines, dependencies, devDependencies } = pkg;
const appVersion = dayjs().format('YYYYMMDDHHmm');
const lastBuildTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
const __APP_INFO__ = {
pkg: { name, version, engines, dependencies, devDependencies },
version: appVersion,
lastBuildTime,
};
/**
* Configuring Vite
*
* @see https://vitejs.dev/config/
*/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
const env = loadEnv(mode, root);
return {
base: './',
plugins: [
vue(),
vueJsx(),
AutoComponents({
dirs: ['./src/components'],
extensions: ['vue', 'jsx', 'tsx'],
dts: './src/auto-components.d.ts',
}),
createHtmlPlugin({
inject: {
data: {
title: env.VITE_APP_TITLE,
},
},
minify: true,
}),
env.VITE_LEGACY === 'true' ? legacy() : null,
],
server: {
host: true,
port: Number(env.VITE_PORT),
proxy: {
'/dev-api': {
target: `https://${env.VITE_APP_API_HOST}/${env.VITE_APP_SUB_DOMAIN}`, // https://api.it120.cc/xiaochengxu
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/dev-api/, ''),
},
},
},
build: {
assetsDir: assetsDir,
sourcemap: false,
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes('node_modules')) return 'vendor';
},
entryFileNames: `${assetsDir}/js/[name].[hash].js`,
chunkFileNames: `${assetsDir}/js/[name].[hash].js`,
assetFileNames: `${assetsDir}/[ext]/[name].[hash].[ext]`,
},
},
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__),
},
css: {
modules: {
localsConvention: 'camelCaseOnly',
},
preprocessorOptions: {
less: {
modifyVars: {
hack: `true; @import './src/styles/variable.less';`,
},
javascriptEnabled: true,
},
},
},
};
});