chore: initial commit
This commit is contained in:
31
frontend/packages/web/config/plugin/compress.ts
Normal file
31
frontend/packages/web/config/plugin/compress.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
|
||||
* gzip压缩
|
||||
* https://github.com/anncwb/vite-plugin-compression
|
||||
*/
|
||||
import type { Plugin } from 'vite';
|
||||
import compressPlugin from 'vite-plugin-compression';
|
||||
|
||||
export default function configCompressPlugin(compress: 'gzip' | 'brotli', deleteOriginFile = false): Plugin | Plugin[] {
|
||||
const plugins: Plugin[] = [];
|
||||
|
||||
if (compress === 'gzip') {
|
||||
plugins.push(
|
||||
compressPlugin({
|
||||
ext: '.gz',
|
||||
deleteOriginFile,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (compress === 'brotli') {
|
||||
plugins.push(
|
||||
compressPlugin({
|
||||
ext: '.br',
|
||||
algorithm: 'brotliCompress',
|
||||
deleteOriginFile,
|
||||
})
|
||||
);
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
18
frontend/packages/web/config/plugin/visualizer.ts
Normal file
18
frontend/packages/web/config/plugin/visualizer.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Generation packaging analysis
|
||||
* 生成打包分析
|
||||
*/
|
||||
import { isReportMode } from '../utils';
|
||||
import visualizer from 'rollup-plugin-visualizer';
|
||||
|
||||
export default function configVisualizerPlugin() {
|
||||
if (isReportMode()) {
|
||||
return visualizer({
|
||||
filename: './node_modules/.cache/visualizer/stats.html',
|
||||
open: true,
|
||||
gzipSize: true,
|
||||
brotliSize: true,
|
||||
});
|
||||
}
|
||||
return [];
|
||||
}
|
||||
9
frontend/packages/web/config/utils/index.ts
Normal file
9
frontend/packages/web/config/utils/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Whether to generate package preview
|
||||
* 是否生成打包报告
|
||||
*/
|
||||
export default {};
|
||||
|
||||
export function isReportMode(): boolean {
|
||||
return process.env.REPORT === 'true';
|
||||
}
|
||||
75
frontend/packages/web/config/vite.config.base.ts
Normal file
75
frontend/packages/web/config/vite.config.base.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||||
import { resolve } from 'path';
|
||||
import AutoImport from 'unplugin-auto-import/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
||||
import vueSetupExtend from 'vite-plugin-vue-setup-extend';
|
||||
import svgLoader from 'vite-svg-loader';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
vueJsx(),
|
||||
vueSetupExtend(),
|
||||
svgLoader({ svgoConfig: {} }),
|
||||
createSvgIconsPlugin({
|
||||
// 指定需要缓存的图标文件夹
|
||||
iconDirs: [resolve(process.cwd(), 'src/assets/svg'), resolve(process.cwd(), 'public/images')], // 与本地储存地址一致
|
||||
// 指定symbolId格式
|
||||
symbolId: 'icon-[name]',
|
||||
}),
|
||||
AutoImport({
|
||||
include: [
|
||||
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
|
||||
/\.vue$/,
|
||||
/\.vue\?vue/, // .vue
|
||||
/\.md$/, // .md
|
||||
],
|
||||
imports: ['vue'],
|
||||
dts: 'src/auto-import.d.ts',
|
||||
eslintrc: {
|
||||
enabled: true, // <-- this
|
||||
},
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: '@locale',
|
||||
replacement: resolve(__dirname, '../src/locale'),
|
||||
},
|
||||
{
|
||||
find: '@',
|
||||
replacement: resolve(__dirname, '../src'),
|
||||
},
|
||||
{
|
||||
find: 'vue-i18n',
|
||||
replacement: 'vue-i18n/dist/vue-i18n.esm-bundler.js', // 解决 vue-i18n 依赖包报错
|
||||
},
|
||||
{
|
||||
find: 'vue',
|
||||
replacement: 'vue/dist/vue.esm-bundler.js', // compile template
|
||||
},
|
||||
],
|
||||
extensions: ['.ts', '.js', '.jsx', '.tsx', '.json', '.vue'],
|
||||
},
|
||||
define: {
|
||||
'process.env': {},
|
||||
// 定义特性标志
|
||||
'__VUE_OPTIONS_API__': true,
|
||||
'__VUE_PROD_DEVTOOLS__': false,
|
||||
// 设置hydration不匹配详细信息的标志
|
||||
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': true,
|
||||
},
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
less: {
|
||||
modifyVars: {
|
||||
hack: `true; @import (reference) "${resolve('src/assets/style/var.less')}";`,
|
||||
},
|
||||
javascriptEnabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
54
frontend/packages/web/config/vite.config.dev.ts
Normal file
54
frontend/packages/web/config/vite.config.dev.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import baseConfig from './vite.config.base';
|
||||
import { config } from 'dotenv';
|
||||
import { mergeConfig } from 'vite';
|
||||
import eslint from 'vite-plugin-eslint';
|
||||
|
||||
// 注入本地/开发配置环境变量(先导入的配置优先级高)
|
||||
config({ path: ['.env.development.local', '.env.development'] });
|
||||
|
||||
export default mergeConfig(
|
||||
{
|
||||
mode: 'development',
|
||||
server: {
|
||||
open: true,
|
||||
fs: {
|
||||
strict: true,
|
||||
},
|
||||
proxy: {
|
||||
'/sse': {
|
||||
target: process.env.VITE_DEV_DOMAIN,
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/front': {
|
||||
target: process.env.VITE_DEV_DOMAIN,
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/front/, ''),
|
||||
},
|
||||
'/pic': {
|
||||
target: process.env.VITE_DEV_DOMAIN,
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/front\/pic/, ''),
|
||||
},
|
||||
'/attachment': {
|
||||
target: process.env.VITE_DEV_DOMAIN,
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/front\/attachment/, ''),
|
||||
},
|
||||
'/ui': {
|
||||
target: process.env.VITE_DEV_DOMAIN,
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/front\/ui/, ''),
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
eslint({
|
||||
overrideConfigFile: 'eslint.config.cjs',
|
||||
cache: false,
|
||||
include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
|
||||
exclude: ['node_modules'],
|
||||
}),
|
||||
],
|
||||
},
|
||||
baseConfig
|
||||
);
|
||||
31
frontend/packages/web/config/vite.config.prod.ts
Normal file
31
frontend/packages/web/config/vite.config.prod.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import configCompressPlugin from './plugin/compress';
|
||||
import configVisualizerPlugin from './plugin/visualizer';
|
||||
import baseConfig from './vite.config.base';
|
||||
import legacy from '@vitejs/plugin-legacy';
|
||||
import { mergeConfig } from 'vite';
|
||||
|
||||
export default mergeConfig(
|
||||
{
|
||||
mode: 'production',
|
||||
plugins: [
|
||||
configCompressPlugin('gzip'),
|
||||
configVisualizerPlugin(),
|
||||
// 兼容性配置,配合package.json中的browserslist使用
|
||||
legacy({
|
||||
targets: ['defaults', 'not IE 11'],
|
||||
}),
|
||||
],
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
vue: ['vue', 'vue-router', 'pinia', '@vueuse/core', 'vue-i18n'],
|
||||
chart: ['echarts', 'vue-echarts'],
|
||||
},
|
||||
},
|
||||
},
|
||||
chunkSizeWarningLimit: 2000,
|
||||
},
|
||||
},
|
||||
baseConfig
|
||||
);
|
||||
Reference in New Issue
Block a user