-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.js
137 lines (136 loc) · 4.26 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
import path from 'node:path';
import { fileURLToPath, URL } from 'node:url';
import tailwind from 'tailwindcss';
import tailwindTypography from '@tailwindcss/typography';
import daisyui from 'daisyui';
import autoprefixer from 'autoprefixer';
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { VitePWA } from 'vite-plugin-pwa';
import Components from 'unplugin-vue-components/vite';
import AutoImport from 'unplugin-auto-import/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import viteCompression from 'vite-plugin-compression';
import manifest from './src/manifest.json';
// https://vitejs.dev/config/
const __dirname = fileURLToPath(new URL('.', import.meta.url));
export default defineConfig({
base: '/',
plugins: [
vue(),
vueJsx(),
Components({
dts: './src/components.d.ts',
extensions: ['vue'],
dirs: ['src/components/'],
}),
AutoImport({
dts: './src/auto-imports.d.ts',
imports: ['vue', 'pinia', 'vue-router'],
eslintrc: {
enabled: false, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
}),
VueI18n({
runtimeOnly: true,
defaultSFCLang:'yml',
compositionOnly: false,
fallbackLocale: 'en',
locale: 'zh-CN',
fullInstall: true,
include: [path.resolve(__dirname, 'src/locales/**')],
}),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'safari-pinned-tab.svg'],
manifest,
}),
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
filename: 'dist/stats.html'
}),
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz',
deleteOriginFile: false
})
],
// 服务设置
server: {
host: true, // host设置为true才可以使用network的形式,以ip访问项目
port: 8087, // 端口号
open: true, // 自动打开浏览器
cors: true, // 跨域设置允许
strictPort: true, // 如果端口已占用直接退出
proxy: {}, // 接口代理
},
build: {
target: 'esnext',
// 启用/禁用 gzip 压缩大小报告
reportCompressedSize: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 500,
minify: 'esbuild',
assetsDir: 'static/assets',
// 静态资源打包到dist下的不同目录
rollupOptions: {
external: ['workbox-window'],
output: {
manualChunks: {
'vue-vendor': ['vue', 'vue-router', 'pinia'],
'echarts-vendor': ['echarts'],
'ui-vendor': ['@iconify/vue'],
},
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
},
},
// 启用 CSS 代码分割
cssCodeSplit: true,
// 启用源码映射
sourcemap: false
},
css: {
preprocessorOptions: {},
postcss: {
plugins: [
tailwind({
daisyui: {
logs: false,
themes: ['light', 'dark', 'cupcake', 'retro', 'dim', 'lemonade'],
},
content: ['./index.html', './src/**/*.{vue,js,jsx}'],
plugins: [tailwindTypography, daisyui],
}),
autoprefixer,
],
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './src/components'),
'@pages': path.resolve(__dirname, './src/pages'),
'@layouts': path.resolve(__dirname, './src/layouts'),
'@stores': path.resolve(__dirname, './src/stores'),
'@assets': path.resolve(__dirname, './src/assets'),
'@enums': path.resolve(__dirname, './src/enums'),
'@hooks': path.resolve(__dirname, './src/hooks'),
'@locales': path.resolve(__dirname, './src/locales'),
'@utils': path.resolve(__dirname, './src/utils'),
'@mock': path.resolve(__dirname, './src/mock'),
'@test': path.resolve(__dirname, './test')
}
},
appType: 'spa',
});