From 90226d70cb405052bd1b9ba4ce314a708bbb6815 Mon Sep 17 00:00:00 2001 From: wangfan <2547096351@qq.com> Date: Sat, 18 Jan 2025 21:40:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BE=9D=E8=B5=96=E9=A2=84=E6=9E=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/_/commit-msg | 6 ++---- .husky/_/pre-commit | 6 ++---- build/optimize.ts | 28 ++++++++++++++++++++++++++++ src/components.d.ts | 30 +++++++++++++++--------------- vite.config.ts | 5 +++++ 5 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 build/optimize.ts diff --git a/.husky/_/commit-msg b/.husky/_/commit-msg index 75dfd99..21c69a4 100644 --- a/.husky/_/commit-msg +++ b/.husky/_/commit-msg @@ -1,4 +1,2 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/husky.sh" - -npx --no-install commitlint --edit $1 +#!/usr/bin/env sh +. "${0%/*}/h" \ No newline at end of file diff --git a/.husky/_/pre-commit b/.husky/_/pre-commit index 469b84f..21c69a4 100644 --- a/.husky/_/pre-commit +++ b/.husky/_/pre-commit @@ -1,4 +1,2 @@ -#!/usr/bin/env sh -. "$(dirname "$0")/husky.sh" - -pnpm run lint:lint-staged +#!/usr/bin/env sh +. "${0%/*}/h" \ No newline at end of file diff --git a/build/optimize.ts b/build/optimize.ts new file mode 100644 index 0000000..3c4a9b0 --- /dev/null +++ b/build/optimize.ts @@ -0,0 +1,28 @@ +/** + * https://cn.vitejs.dev/config/dep-optimization-options#optimizedeps-exclude + * 在 Vite 的配置文件 vite.config.ts 中,optimizeDeps 选项用于配置依赖优化,特别是预构建步骤,以提高开发和构建性能。 + * 这种情况尤其需要注意,当你禁止浏览器缓存时就必须将对应模块加载到依赖预构建,否则跳转时会频繁出现页面刷新的问题,因为它无法在浏览器缓存也没有在本地node_modules/.vite内缓存。 + * 如果使用的第三方库是全局引入,也就是src/main.ts文件里,那么它就会自动被vite缓存到node_modules/.vite,此时就不用将该第三方库做依赖预构建(添加到include内)。 + */ +const include = [ + "vue-codemirror6", + "qrcode", + "jsbarcode", + "vuedraggable", + "@wangeditor/editor", + "fingerprintjs2", + "xgplayer", + "print-js", + "@codemirror/theme-one-dark", + "@codemirror/lang-json", + "@codemirror/lang-javascript", + "@codemirror/lang-vue" +]; + +/** + * 在预构建中强制排除的依赖项 + * 如果你有某些依赖包不希望被预构建,可以使用 exclude 属性来排除它们。 + */ +// const exclude = []; + +export { include }; diff --git a/src/components.d.ts b/src/components.d.ts index 408d21a..cfb0bc8 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -5,21 +5,21 @@ // Read more: https://github.com/vuejs/core/pull/3399 export {} -declare module "vue" { +declare module 'vue' { export interface GlobalComponents { - BarcodeDraw: (typeof import("./components/barcode-draw/index.vue"))["default"]; - CodeView: (typeof import("./components/code-view/index.vue"))["default"]; - ExternalLinkPage: (typeof import("./components/external-link-page/index.vue"))["default"]; - FillPage: (typeof import("./components/fill-page/index.vue"))["default"]; - InternalLinkPage: (typeof import("./components/internal-link-page/index.vue"))["default"]; - LangProvider: (typeof import("./components/lang-provider/index.vue"))["default"]; - MainTransition: (typeof import("./components/main-transition/index.vue"))["default"]; - QrcodeDraw: (typeof import("./components/qrcode-draw/index.vue"))["default"]; - RouterLink: (typeof import("vue-router"))["RouterLink"]; - RouterView: (typeof import("vue-router"))["RouterView"]; - SelectIcon: (typeof import("./components/select-icon/index.vue"))["default"]; - SvgAndIcon: (typeof import("./components/svg-and-icon/index.vue"))["default"]; - SvgIcon: (typeof import("./components/svg-icon/index.vue"))["default"]; - VerifyCode: (typeof import("./components/verify-code/index.vue"))["default"]; + BarcodeDraw: typeof import('./components/barcode-draw/index.vue')['default'] + CodeView: typeof import('./components/code-view/index.vue')['default'] + ExternalLinkPage: typeof import('./components/external-link-page/index.vue')['default'] + FillPage: typeof import('./components/fill-page/index.vue')['default'] + InternalLinkPage: typeof import('./components/internal-link-page/index.vue')['default'] + LangProvider: typeof import('./components/lang-provider/index.vue')['default'] + MainTransition: typeof import('./components/main-transition/index.vue')['default'] + QrcodeDraw: typeof import('./components/qrcode-draw/index.vue')['default'] + RouterLink: typeof import('vue-router')['RouterLink'] + RouterView: typeof import('vue-router')['RouterView'] + SelectIcon: typeof import('./components/select-icon/index.vue')['default'] + SvgAndIcon: typeof import('./components/svg-and-icon/index.vue')['default'] + SvgIcon: typeof import('./components/svg-icon/index.vue')['default'] + VerifyCode: typeof import('./components/verify-code/index.vue')['default'] } } diff --git a/vite.config.ts b/vite.config.ts index e268bdb..270e17a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,7 @@ import { defineConfig, normalizePath, loadEnv } from "vite"; import path from "path"; import { resolve } from "path"; +import { include } from "./build/optimize"; import postcssPresetEnv from "postcss-preset-env"; import { createVitePlugins } from "./build/vite-plugin"; const themePath = normalizePath(path.normalize("./src/style/global-theme.scss")); @@ -47,6 +48,10 @@ export default defineConfig(({ mode }) => { } } }, + // https://cn.vitejs.dev/config/dep-optimization-options.html#dep-optimization-options + optimizeDeps: { + include + }, build: { outDir: "dist", // 指定打包路径,默认为项目根目录下的dist目录 // minify: "esbuild", // esbuild打包更快但是不能去除console.log,terser打包慢但能去除console.log