|
|
@@ -7,6 +7,7 @@ import { buildConfig } from './src/utils/build';
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
import { CodeInspectorPlugin } from 'code-inspector-plugin';
|
|
|
import fs from 'fs';
|
|
|
+import { visualizer } from 'rollup-plugin-visualizer';
|
|
|
|
|
|
const pathResolve = (dir: string) => {
|
|
|
return resolve(__dirname, '.', dir);
|
|
|
@@ -22,6 +23,7 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
|
|
|
fs.writeFileSync('./public/config.js', `window.__env__ = ${JSON.stringify(env, null, 2)} `);
|
|
|
return {
|
|
|
plugins: [
|
|
|
+ visualizer({ open: true }), // 自动开启分析页面
|
|
|
CodeInspectorPlugin({
|
|
|
bundler: 'vite',
|
|
|
hotKeys: ['shiftKey'],
|
|
|
@@ -30,13 +32,12 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
|
|
|
vueJsx(),
|
|
|
vueSetupExtend(),
|
|
|
viteCompression({
|
|
|
- verbose: true, // 默认即可
|
|
|
- disable: false, // 开启压缩(不禁用),默认即可
|
|
|
- deleteOriginFile: false, // 删除源文件
|
|
|
- // 对所有大于 5KB 的文件进行 gzip 压缩
|
|
|
- threshold: 5120, // the unit is Bytes
|
|
|
- algorithm: 'gzip', // 压缩算法
|
|
|
- ext: '.gz', // 文件类型
|
|
|
+ verbose: true, // 是否在控制台中输出压缩结果
|
|
|
+ disable: false, // 是否禁用压缩
|
|
|
+ deleteOriginFile: true, // 压缩后是否删除源文件
|
|
|
+ threshold: 5120, // 对大于 5KB 文件进行 gzip 压缩,单位Bytes
|
|
|
+ algorithm: 'gzip', // 压缩算法,可选[‘gzip’,‘brotliCompress’,‘deflate’,‘deflateRaw’]
|
|
|
+ ext: '.gz', // 生成的压缩包的后缀
|
|
|
}),
|
|
|
JSON.parse(env.VITE_OPEN_CDN) ? buildConfig.cdn() : null,
|
|
|
],
|
|
|
@@ -50,12 +51,6 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
|
|
|
open: JSON.parse(env.VITE_OPEN),
|
|
|
hmr: true,
|
|
|
proxy: {
|
|
|
- '/gitee': {
|
|
|
- target: 'https://gitee.com',
|
|
|
- ws: true,
|
|
|
- changeOrigin: true,
|
|
|
- rewrite: (path) => path.replace(/^\/gitee/, ''),
|
|
|
- },
|
|
|
'^/[Uu]pload': {
|
|
|
target: env.VITE_API_URL,
|
|
|
changeOrigin: true,
|
|
|
@@ -67,18 +62,19 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
|
|
|
chunkSizeWarningLimit: 1500,
|
|
|
assetsInlineLimit: 5000, // 小于此阈值的导入或引用资源将内联为 base64 编码
|
|
|
sourcemap: false, // 构建后是否生成 source map 文件
|
|
|
+ extractComments: false, // 移除注释
|
|
|
+ minify: 'terser', // 启用后 terserOptions 配置才有效
|
|
|
terserOptions: {
|
|
|
compress: {
|
|
|
- //生产环境时移除console
|
|
|
- drop_console: true,
|
|
|
+ drop_console: true, // 生产环境时移除console
|
|
|
drop_debugger: true,
|
|
|
},
|
|
|
},
|
|
|
rollupOptions: {
|
|
|
output: {
|
|
|
- chunkFileNames: 'assets/js/[name]-[hash].js',
|
|
|
- entryFileNames: 'assets/js/[name]-[hash].js',
|
|
|
- assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
|
|
|
+ chunkFileNames: 'assets/js/[name]-[hash].js', // 引入文件名的名称
|
|
|
+ entryFileNames: 'assets/js/[name]-[hash].js', // 包的入口文件名称
|
|
|
+ assetFileNames: 'assets/[ext]/[name]-[hash].[ext]', // 资源文件像 字体,图片等
|
|
|
manualChunks(id) {
|
|
|
if (id.includes('node_modules')) {
|
|
|
let newId = id.toString().replace('/.', '/');
|