Skip to content

Commit

Permalink
refactor: 按需导入
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 24, 2023
1 parent 09c7a2d commit 7631c3b
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 8 deletions.
8 changes: 8 additions & 0 deletions auto-imports.d.ts
@@ -0,0 +1,8 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-auto-import
export {}
declare global {

}
26 changes: 26 additions & 0 deletions components.d.ts
@@ -0,0 +1,26 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'

export {}

declare module '@vue/runtime-core' {
export interface GlobalComponents {
ChangeLocal: typeof import('./src/components/set/preference/ChangeLocal.vue')['default']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElOption: typeof import('element-plus/es')['ElOption']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElTabPane: typeof import('element-plus/es')['ElTabPane']
ElTabs: typeof import('element-plus/es')['ElTabs']
GeneralSetting: typeof import('./src/components/set/GeneralSetting.vue')['default']
PublishIndex: typeof import('./src/components/publish/PublishIndex.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
SetIndex: typeof import('./src/components/set/SetIndex.vue')['default']
}
}
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -28,6 +28,8 @@
"rollup-plugin-livereload": "^2.0.5",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"unplugin-auto-import": "^0.16.2",
"unplugin-vue-components": "^0.24.1",
"vercel": "^29.4.0",
"vite": "^4.3.2",
"vite-plugin-html": "^3.2.0",
Expand Down
135 changes: 128 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/main.ts
Expand Up @@ -60,7 +60,9 @@ import { AppInstance } from "~/src/appInstance.ts"
app.provide(InjectKeys.APP_INSTANCE, appInstance)

// ElementPlus
app.use(ElementPlus)
// 包太大,需要改成按需引入
// https://element-plus.org/zh-CN/guide/quickstart.html#%E6%8C%89%E9%9C%80%E5%AF%BC%E5%85%A5
// app.use(ElementPlus)

// 挂载 vue app
app.mount("#app")
Expand Down
25 changes: 25 additions & 0 deletions vite.config.ts
Expand Up @@ -6,6 +6,9 @@ import fg from "fast-glob"
import { createHtmlPlugin } from "vite-plugin-html"
import path from "path"
import commonjs from "@rollup/plugin-commonjs"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver } from "unplugin-vue-components/resolvers"

const getAppBase = (isSiyuanBuild: boolean, isStaticBuild: boolean): string => {
if (isSiyuanBuild) {
Expand Down Expand Up @@ -42,6 +45,13 @@ export default defineConfig({
plugins: [
vue(),

AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),

createHtmlPlugin({
minify: !isDev,
inject: {
Expand Down Expand Up @@ -149,6 +159,21 @@ export default defineConfig({
// console.log("id=>", id)
// console.log("dep=>", dep)
if (dep !== "") {
// if (dep === "element-plus") {
// let element_dep = dep
// const componentPath = id
// const componentRegex = /\/node_modules\/([^/]+)\/.*\/components\/([^/]+)/
// const matches = componentPath.match(componentRegex)
//
// if (matches !== null) {
// element_dep = matches[2]
// // console.log("element_dep=>", element_dep)
// } else {
// // console.log(`Could not match component name from ${componentPath}`)
// }
//
// return "vendor_element_plus_" + element_dep
// }
return "vendor_" + dep
}
return "vendor"
Expand Down

0 comments on commit 7631c3b

Please sign in to comment.