Skip to content

Commit

Permalink
feature: add visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Sep 25, 2022
1 parent 76a63ac commit 04ec10e
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build/vite/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function createViteBuild(): BuildOptions {
sourcemap: false,
// 启用/禁用 brotli 压缩大小报告。压缩大型输出文件可能会很慢,因此禁用该功能可能会提高大型项目的构建性能。
brotliSize: false,
// minify: 'terser',
// terserOptions: {
// compress: {
// keep_infinity: true,
// // Used to delete console in production environment
// // 打包清除console
// drop_console: true,
// },
// },
Expand Down
9 changes: 9 additions & 0 deletions build/vite/esbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://cn.vitejs.dev/config/shared-options.html#esbuild

import { ESBuildOptions } from 'vite';

export function createViteEsbuild(isBuild: boolean): ESBuildOptions | false {
return {
pure: isBuild ? ['console'] : [],
};
}
4 changes: 4 additions & 0 deletions build/vite/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { configCompressPlugin } from './compress';
import { configMockPlugin } from './mock';
// pwd
import { configPwaPlugin } from './pwa';
// 性能分析工具
import { configVisualizerPlugin } from './visualizer';
// 按需element样式
import ElementPlus from 'unplugin-element-plus/vite';
// setip使用Options API
Expand Down Expand Up @@ -45,6 +47,8 @@ export function createVitePlugins(isBuild = false, _configEnv: ConfigEnv) {

vitePlugins.push(configPwaPlugin());

vitePlugins.push(configVisualizerPlugin());

vitePlugins.push(DefineOptions());

vitePlugins.push(viteBuildOuteInfo());
Expand Down
19 changes: 19 additions & 0 deletions build/vite/plugin/visualizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// https://github.com/btd/rollup-plugin-visualizer
import visualizer from 'rollup-plugin-visualizer';

import type { Plugin } from 'vite';

export function configVisualizerPlugin(): Plugin | Plugin[] {
if (process.env.REPORT === 'true') {
return [
visualizer({
filename: './node_modules/.cache/visualizer/stats.html',
open: true,
gzipSize: true,
brotliSize: true,
}) as Plugin,
];
} else {
return [];
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"type:check": "vue-tsc --noEmit --skipLibCheck",
"preview": "npm run build && vite preview",
"preview:dist": "vite preview",
"visualizer": "cross-env REPORT=true npm run build",
"log": "conventional-changelog -p cmyr-config -i CHANGELOG.md -s -r 0",
"test": "vitest",
"test:ui": "vitest --ui",
Expand Down Expand Up @@ -82,6 +83,7 @@
"autoprefixer": "^10.4.8",
"commitizen": "^4.2.5",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"crypto-js": "^4.1.1",
"cz-conventional-changelog": "^3.3.0",
"cz-customizable": "^6.9.1",
Expand All @@ -103,6 +105,7 @@
"postcss-scss": "^4.0.4",
"prettier": "2.7.1",
"pretty-quick": "^3.1.3",
"rollup-plugin-visualizer": "^5.8.1",
"sass": "^1.54.5",
"stylelint": "^14.11.0",
"stylelint-config-prettier": "^9.0.3",
Expand All @@ -123,7 +126,8 @@
"vite-plugin-svg-icons": "^2.0.1",
"vitest": "^0.23.4",
"vue-eslint-parser": "^9.0.3",
"vue-tsc": "^0.40.1"
"vue-tsc": "^0.40.1",
"xlsx": "^0.18.5"
},
"license": "MIT",
"pnpm": {
Expand Down
Loading

0 comments on commit 04ec10e

Please sign in to comment.