From d4aebef89cfb94c0267ddf8e5878552eeb378812 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 17 Jan 2022 15:43:54 +0800 Subject: [PATCH] chore(@vant/cli): remove lodash-es from deps (#10206) --- packages/vant-cli/package.json | 2 -- packages/vant-cli/src/common/constant.ts | 3 +-- packages/vant-cli/src/common/css.ts | 5 ++--- packages/vant-cli/src/common/index.ts | 3 +-- .../vant-cli/src/compiler/gen-package-entry.ts | 5 ++--- .../vant-cli/src/compiler/gen-vetur-config.ts | 3 +-- packages/vant-cli/src/config/vite.site.ts | 11 +++++------ pnpm-lock.yaml | 18 ------------------ 8 files changed, 12 insertions(+), 38 deletions(-) diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index ec39c3143..d96a8843f 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -41,7 +41,6 @@ "devDependencies": { "@types/fs-extra": "^9.0.13", "@types/less": "^3.0.3", - "@types/lodash-es": "^4.17.5", "@types/markdown-it": "^12.2.3", "vue": "^3.2.27" }, @@ -77,7 +76,6 @@ "jest-serializer-html": "^7.1.0", "less": "^4.1.2", "lint-staged": "^12.1.2", - "lodash-es": "^4.17.21", "markdown-it": "^12.2.0", "markdown-it-anchor": "^8.4.1", "ora": "^6.0.1", diff --git a/packages/vant-cli/src/common/constant.ts b/packages/vant-cli/src/common/constant.ts index 4cdc78822..229177a08 100644 --- a/packages/vant-cli/src/common/constant.ts +++ b/packages/vant-cli/src/common/constant.ts @@ -1,4 +1,3 @@ -import { get } from 'lodash-es'; import { existsSync, readFileSync } from 'fs'; import { fileURLToPath, pathToFileURL } from 'url'; import { join, dirname, isAbsolute } from 'path'; @@ -74,7 +73,7 @@ export function getVantConfig() { function getSrcDir() { const vantConfig = getVantConfig(); - const srcDir = get(vantConfig, 'build.srcDir'); + const srcDir = vantConfig.build?.srcDir; if (srcDir) { if (isAbsolute(srcDir)) { diff --git a/packages/vant-cli/src/common/css.ts b/packages/vant-cli/src/common/css.ts index 2aad2021d..98f5679cd 100644 --- a/packages/vant-cli/src/common/css.ts +++ b/packages/vant-cli/src/common/css.ts @@ -1,4 +1,3 @@ -import { get } from 'lodash-es'; import { existsSync } from 'fs'; import { join, isAbsolute } from 'path'; import { getVantConfig } from '../common/index.js'; @@ -8,7 +7,7 @@ type CSS_LANG = 'css' | 'less' | 'scss'; function getCssLang(): CSS_LANG { const vantConfig = getVantConfig(); - const preprocessor = get(vantConfig, 'build.css.preprocessor', 'less'); + const preprocessor = vantConfig.build?.css?.preprocessor || 'less'; if (preprocessor === 'sass') { return 'scss'; @@ -23,7 +22,7 @@ export function getCssBaseFile() { const vantConfig = getVantConfig(); let path = join(STYLE_DIR, `base.${CSS_LANG}`); - const baseFile = get(vantConfig, 'build.css.base', ''); + const baseFile = vantConfig.build?.css?.base || ''; if (baseFile) { path = isAbsolute(baseFile) ? baseFile : join(SRC_DIR, baseFile); } diff --git a/packages/vant-cli/src/common/index.ts b/packages/vant-cli/src/common/index.ts index f057c7f03..2bbe6d085 100644 --- a/packages/vant-cli/src/common/index.ts +++ b/packages/vant-cli/src/common/index.ts @@ -1,5 +1,4 @@ import fse from 'fs-extra'; -import { get } from 'lodash-es'; import { sep, join } from 'path'; import { SRC_DIR, getVantConfig } from './constant.js'; import type { InlineConfig } from 'vite'; @@ -117,7 +116,7 @@ export function smartOutputFile(filePath: string, content: string) { export function mergeCustomViteConfig(config: InlineConfig) { const vantConfig = getVantConfig(); - const configureVite = get(vantConfig, 'build.configureVite'); + const configureVite = vantConfig.build?.configureVite; if (configureVite) { return configureVite(config); diff --git a/packages/vant-cli/src/compiler/gen-package-entry.ts b/packages/vant-cli/src/compiler/gen-package-entry.ts index cf4e1be7c..65510da1a 100644 --- a/packages/vant-cli/src/compiler/gen-package-entry.ts +++ b/packages/vant-cli/src/compiler/gen-package-entry.ts @@ -1,4 +1,3 @@ -import { get } from 'lodash-es'; import { join } from 'path'; import { pascalize, @@ -72,8 +71,8 @@ export function genPackageEntry({ const names = getComponents(); const vantConfig = getVantConfig(); - const namedExport = get(vantConfig, 'build.namedExport', false); - const skipInstall = get(vantConfig, 'build.skipInstall', []).map(pascalize); + const namedExport = vantConfig.build?.namedExport || false; + const skipInstall = (vantConfig.build?.skipInstall || []).map(pascalize); const version = process.env.PACKAGE_VERSION || getPackageJson().version; diff --git a/packages/vant-cli/src/compiler/gen-vetur-config.ts b/packages/vant-cli/src/compiler/gen-vetur-config.ts index 52060eddd..eb1209ba4 100644 --- a/packages/vant-cli/src/compiler/gen-vetur-config.ts +++ b/packages/vant-cli/src/compiler/gen-vetur-config.ts @@ -1,5 +1,4 @@ import markdownVetur from '@vant/markdown-vetur'; -import { get } from 'lodash-es'; import { SRC_DIR, VETUR_DIR, @@ -11,7 +10,7 @@ import { export function genVeturConfig() { const pkgJson = getPackageJson(); const vantConfig = getVantConfig(); - const options = get(vantConfig, 'build.vetur'); + const options = vantConfig.build?.vetur; if (options) { markdownVetur.parseAndWrite({ diff --git a/packages/vant-cli/src/config/vite.site.ts b/packages/vant-cli/src/config/vite.site.ts index 96df20e36..f883904ed 100644 --- a/packages/vant-cli/src/config/vite.site.ts +++ b/packages/vant-cli/src/config/vite.site.ts @@ -1,5 +1,4 @@ import { join } from 'path'; -import { get } from 'lodash-es'; import { createRequire } from 'module'; import hljs from 'highlight.js'; import vitePluginMd from 'vite-plugin-md'; @@ -82,7 +81,7 @@ function getTitle(config: { title: string; description?: string }) { } function getHTMLMeta(vantConfig: any) { - const meta = get(vantConfig, 'site.htmlMeta'); + const meta = vantConfig.site?.htmlMeta; if (meta) { return Object.keys(meta) @@ -99,8 +98,8 @@ export function getViteConfigForSiteDev(): InlineConfig { const vantConfig = getVantConfig(); const siteConfig = getSiteConfig(vantConfig); const title = getTitle(siteConfig); - const baiduAnalytics = get(vantConfig, 'site.baiduAnalytics'); - const enableVConsole = isDev() && get(vantConfig, 'site.enableVConsole'); + const baiduAnalytics = vantConfig.site?.baiduAnalytics; + const enableVConsole = isDev() && vantConfig.site?.enableVConsole; return { root: SITE_SRC_DIR, @@ -162,8 +161,8 @@ export function getViteConfigForSiteDev(): InlineConfig { export function getViteConfigForSiteProd(): InlineConfig { const devConfig = getViteConfigForSiteDev(); const vantConfig = getVantConfig(); - const outDir = get(vantConfig, 'build.site.outputDir', SITE_DIST_DIR); - const publicPath = get(vantConfig, 'build.site.publicPath', '/'); + const outDir = vantConfig.build?.site?.outputDir || SITE_DIST_DIR; + const publicPath = vantConfig.build?.site?.publicPath || '/'; return { ...devConfig, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c33b2851..a20418813 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -93,7 +93,6 @@ importers: '@types/fs-extra': ^9.0.13 '@types/jest': ^27.0.3 '@types/less': ^3.0.3 - '@types/lodash-es': ^4.17.5 '@types/markdown-it': ^12.2.3 '@vant/eslint-config': ^3.3.2 '@vant/markdown-vetur': ^2.2.0 @@ -121,7 +120,6 @@ importers: jest-serializer-html: ^7.1.0 less: ^4.1.2 lint-staged: ^12.1.2 - lodash-es: ^4.17.21 markdown-it: ^12.2.0 markdown-it-anchor: ^8.4.1 ora: ^6.0.1 @@ -169,7 +167,6 @@ importers: jest-serializer-html: 7.1.0 less: 4.1.2 lint-staged: 12.1.2 - lodash-es: 4.17.21 markdown-it: 12.2.0 markdown-it-anchor: 8.4.1_b5b6ac618dbcb305e9dd9bd86fa4e841 ora: 6.0.1 @@ -187,7 +184,6 @@ importers: devDependencies: '@types/fs-extra': 9.0.13 '@types/less': 3.0.3 - '@types/lodash-es': 4.17.5 '@types/markdown-it': 12.2.3 vue: 3.2.27 @@ -1585,16 +1581,6 @@ packages: /@types/linkify-it/3.0.2: resolution: {integrity: sha1-/SzS7bqn6qx+fzwXSLUqGRQ4Rsk=, tarball: '@types/linkify-it/download/@types/linkify-it-3.0.2.tgz'} - /@types/lodash-es/4.17.5: - resolution: {integrity: sha1-HD/dFoSdhK6kOJCxxg2jeftQE1M=, tarball: '@types/lodash-es/download/@types/lodash-es-4.17.5.tgz'} - dependencies: - '@types/lodash': 4.14.176 - dev: true - - /@types/lodash/4.14.176: - resolution: {integrity: sha1-ZBFQ/BzaNvv6Mp3mA7uxddfuIMA=, tarball: '@types/lodash/download/@types/lodash-4.14.176.tgz'} - dev: true - /@types/markdown-it/12.2.3: resolution: {integrity: sha1-DW9uXkE/jaqiZSKQRZe+PWzZO1E=, tarball: '@types/markdown-it/download/@types/markdown-it-12.2.3.tgz'} dependencies: @@ -5508,10 +5494,6 @@ packages: dependencies: p-locate: 4.1.0 - /lodash-es/4.17.21: - resolution: {integrity: sha1-Q+YmxG5lkbd1C+srUBFzkMYJ4+4=, tarball: lodash-es/download/lodash-es-4.17.21.tgz?cache=0&sync_timestamp=1632822762695&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Flodash-es%2Fdownload%2Flodash-es-4.17.21.tgz} - dev: false - /lodash.ismatch/4.4.0: resolution: {integrity: sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=, tarball: lodash.ismatch/download/lodash.ismatch-4.4.0.tgz} dev: false