Skip to content

Commit

Permalink
🛠移除 lodash-es 依赖
Browse files Browse the repository at this point in the history
- 在多个文件中替换 lodash-es 的使用,使用自定义实现或其他替代方案
- 优化了 vite 配置文件,更新了手动refactor(depend分块依赖列表
  • Loading branch information
0xcaffebabe committed Oct 30, 2024
1 parent 856e6af commit 288be87
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 12 deletions.
68 changes: 68 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}

/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
CategorySearch: typeof import('./src/components/search/CategorySearch.vue')['default']
ElAffix: typeof import('element-plus/es')['ElAffix']
ElAside: typeof import('element-plus/es')['ElAside']
ElAutocomplete: typeof import('element-plus/es')['ElAutocomplete']
ElBacktop: typeof import('element-plus/es')['ElBacktop']
ElBadge: typeof import('element-plus/es')['ElBadge']
ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb']
ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem']
ElButton: typeof import('element-plus/es')['ElButton']
ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
ElCard: typeof import('element-plus/es')['ElCard']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElCol: typeof import('element-plus/es')['ElCol']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElDescriptions: typeof import('element-plus/es')['ElDescriptions']
ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElDivider: typeof import('element-plus/es')['ElDivider']
ElDrawer: typeof import('element-plus/es')['ElDrawer']
ElDropdown: typeof import('element-plus/es')['ElDropdown']
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
ElEmpty: typeof import('element-plus/es')['ElEmpty']
ElHeader: typeof import('element-plus/es')['ElHeader']
ElIcon: typeof import('element-plus/es')['ElIcon']
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
ElInput: typeof import('element-plus/es')['ElInput']
ElLink: typeof import('element-plus/es')['ElLink']
ElMain: typeof import('element-plus/es')['ElMain']
ElOption: typeof import('element-plus/es')['ElOption']
ElPopconfirm: typeof import('element-plus/es')['ElPopconfirm']
ElRadio: typeof import('element-plus/es')['ElRadio']
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
ElRow: typeof import('element-plus/es')['ElRow']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSkeleton: typeof import('element-plus/es')['ElSkeleton']
ElSlider: typeof import('element-plus/es')['ElSlider']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
ElTable: typeof import('element-plus/es')['ElTable']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
ElTabPane: typeof import('element-plus/es')['ElTabPane']
ElTabs: typeof import('element-plus/es')['ElTabs']
ElTag: typeof import('element-plus/es')['ElTag']
ElTimeline: typeof import('element-plus/es')['ElTimeline']
ElTimelineItem: typeof import('element-plus/es')['ElTimelineItem']
Header: typeof import('./src/components/header/Header.vue')['default']
ImageViewer: typeof import('./src/components/ImageViewer.vue')['default']
Mind: typeof import('./src/components/mind/Mind.vue')['default']
MobileHeader: typeof import('./src/components/header/mobile/MobileHeader.vue')['default']
MobileImageViewer: typeof import('./src/components/mobile/MobileImageViewer.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Search: typeof import('./src/components/search/Search.vue')['default']
ThemeSwitcher: typeof import('./src/components/header/ThemeSwitcher.vue')['default']
}
export interface ComponentCustomProperties {
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
}
}
2 changes: 0 additions & 2 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"jsmind": "0.8.5",
"katex": "0.16.11",
"less": "4.2.0",
"lodash-es": "4.17.21",
"marked": "14.1.2",
"mermaid": "11.3.0",
"nprogress": "0.2.0",
Expand All @@ -36,7 +35,6 @@
"@types/js-yaml": "4.0.9",
"@types/jsdom": "21.1.7",
"@types/katex": "0.16.7",
"@types/lodash": "4.17.10",
"@types/node": "22.7.5",
"@types/nprogress": "0.2.3",
"@types/prismjs": "1.26.4",
Expand Down
7 changes: 6 additions & 1 deletion src/pages/doc/ToolBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@
<script lang="ts">
import { defineComponent } from "vue";
import {Tools} from '@element-plus/icons-vue'
import {random} from 'lodash-es'
import Category from "@/dto/Category";
import CategoryService from "@/service/CategoryService";
import DocUtils from "@/util/DocUtils";
function random(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
type ActionType =
'showReadingHistory' |
'showMindGraph' |
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/statistic/CommitTotalTrend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { LineChart, LineSeriesOption } from 'echarts/charts';
import { UniversalTransition } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';
import {cloneDeep} from 'lodash-es'
import {cloneDeep} from '@/util/DataUtils'
echarts.use([
TitleComponent,
Expand Down Expand Up @@ -74,7 +74,7 @@ export default defineComponent({
},
methods: {
async init() {
const data = cloneDeep(await api.getCommitTotalTrend());
const data = cloneDeep(await api.getCommitTotalTrend()) as [string, number, number, number][];
const myChart = echarts.init(this.$refs.chartContainer as HTMLElement);
if (this.type === 'relative') {
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/generateDocCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import util from 'util'
import { cleanText } from '../util/StringUtils';
import ClusterNode from '../dto/ClusterNode';
import jieba from 'nodejieba'
import {cloneDeep} from 'lodash-es'
import {cloneDeep} from '../util/DataUtils'

const reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");

Expand Down Expand Up @@ -184,7 +184,7 @@ function getDocVec(file: string): number[] {
.filter(v => !isStopWord(v))
.forEach(i => map.set(i, (map.get(i) || 0) + 1))

const list = cloneDeep(totalList)
const list = cloneDeep(totalList) as [string, number][]
list.forEach(v => v[1] = map.get(v[0]) || 0)
const vec = list.map(v => v[1])
vecCache.set(file, vec)
Expand Down
4 changes: 2 additions & 2 deletions src/test/SplitWord.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BaseService from "../build/BaseService"
import fs from 'fs'
import jieba from 'nodejieba'
import {cloneDeep} from 'lodash-es'
import {cloneDeep} from '../util/DataUtils'

const stopWords = ['的', '是', '在', '一个', '和',
'与', '批注', '可以', '使用', '通过', 'md', '据库', '这个', '截图', '没有',
Expand Down Expand Up @@ -60,7 +60,7 @@ function getDocVec(doc: string): number[] {
.filter(v => !isStopWord(v))
.forEach(i => map.set(i, (map.get(i) || 0) + 1))

const list = cloneDeep(totalList)
const list = cloneDeep(totalList) as [string, number][]
list.forEach(v => v[1] = map.get(v[0]) || 0)
return list.map(v => v[1])
}
Expand Down
4 changes: 4 additions & 0 deletions src/util/DataUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function cloneDeep(obj: any) {
return JSON.parse(JSON.stringify(obj))
}
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default defineConfig({
manualChunks(id: string): string {
const indepentDependcies = ['element-plus', 'vue', 'jspdf',
'html2canvas', 'echarts', 'zrender', 'marked', 'mermaid',
'katex', 'lodash-es', 'elkjs', 'cytoscape']
'katex', 'elkjs', 'cytoscape']
for (let depend of indepentDependcies) {
if (id.includes('node_modules') && id.includes(depend)) {
return depend
Expand Down

0 comments on commit 288be87

Please sign in to comment.