From fad44923fb21be0cc859ea8ebc91d7bfa8ca95c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Sat, 21 Dec 2019 08:55:22 +0800 Subject: [PATCH] fix(cli): should check style exists when gen component style entry --- packages/vant-cli/src/compiler/gen-component-style.ts | 9 ++++++++- packages/vant-cli/src/compiler/gen-style-deps-map.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/vant-cli/src/compiler/gen-component-style.ts b/packages/vant-cli/src/compiler/gen-component-style.ts index 8d1372afd..26bbb0c41 100644 --- a/packages/vant-cli/src/compiler/gen-component-style.ts +++ b/packages/vant-cli/src/compiler/gen-component-style.ts @@ -6,6 +6,7 @@ import { join, relative } from 'path'; import { outputFileSync } from 'fs-extra'; import { getComponents, replaceExt } from '../common'; import { CSS_LANG, getCssBaseFile } from '../common/css'; +import { checkStyleExists } from './gen-style-deps-map'; import { ES_DIR, SRC_DIR, @@ -17,7 +18,13 @@ function getDeps(component: string): string[] { const styleDepsJson = require(STYPE_DEPS_JSON_FILE); if (styleDepsJson.map[component]) { - return [...styleDepsJson.map[component], component]; + const deps = styleDepsJson.map[component].slice(0); + + if (checkStyleExists(component)) { + deps.push(component); + } + + return deps; } return []; diff --git a/packages/vant-cli/src/compiler/gen-style-deps-map.ts b/packages/vant-cli/src/compiler/gen-style-deps-map.ts index 6d8c81e33..274c25cbc 100644 --- a/packages/vant-cli/src/compiler/gen-style-deps-map.ts +++ b/packages/vant-cli/src/compiler/gen-style-deps-map.ts @@ -18,7 +18,7 @@ function getStylePath(component: string) { return join(SRC_DIR, `${component}/index.${CSS_LANG}`); } -function checkStyleExists(component: string) { +export function checkStyleExists(component: string) { return existsSync(getStylePath(component)); }