forked from rarnu/tools-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
46 lines (44 loc) · 1000 Bytes
/
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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import viteCompression from 'vite-plugin-compression';
import path from 'path';
import fs from 'fs';
// 保存配置文件
function saveConfig() {
if (process.env.NODE_ENV === 'production') {
const config = {
updateTime: new Date().getTime(),
};
fs.writeFileSync('./src/assets/json/config.json', JSON.stringify(config));
}
return {
name: 'save-config',
};
}
export default defineConfig({
base: './',
plugins: [
vue(),
viteCompression({
threshold: 10240, // 超过10k压缩
}),
saveConfig(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'], // 扩展了.vue后缀
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import './src/styles/variable.scss';`,
},
},
},
server: {
host: '0.0.0.0',
port: 8010,
},
});