From 1d8e2654f56a28ca77f7bcadf023f6a2b0d694f9 Mon Sep 17 00:00:00 2001 From: yinhui1129754 <375361172@qq.com> Date: Fri, 14 Feb 2020 14:37:19 +0800 Subject: [PATCH] fix(vant-cli): fix Windows system build style problems (#5655) --- packages/vant-cli/src/common/index.ts | 6 +++--- packages/vant-cli/src/compiler/gen-component-style.ts | 4 ++-- packages/vant-cli/src/compiler/gen-style-deps-map.ts | 9 ++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/vant-cli/src/common/index.ts b/packages/vant-cli/src/common/index.ts index 0d01f02ae..a10b3bb4c 100644 --- a/packages/vant-cli/src/common/index.ts +++ b/packages/vant-cli/src/common/index.ts @@ -1,4 +1,4 @@ -import { join } from 'path'; +import { sep, join } from 'path'; import { lstatSync, existsSync, @@ -15,8 +15,8 @@ import { export const EXT_REGEXP = /\.\w+$/; export const SFC_REGEXP = /\.(vue)$/; -export const DEMO_REGEXP = /\/demo$/; -export const TEST_REGEXP = /\/test$/; +export const DEMO_REGEXP = new RegExp('\\' + sep + 'demo$'); +export const TEST_REGEXP = new RegExp('\\' + sep + 'test$'); export const STYLE_REGEXP = /\.(css|less|scss)$/; export const SCRIPT_REGEXP = /\.(js|ts|jsx|tsx)$/; export const ENTRY_EXTS = ['js', 'ts', 'tsx', 'jsx', 'vue']; diff --git a/packages/vant-cli/src/compiler/gen-component-style.ts b/packages/vant-cli/src/compiler/gen-component-style.ts index e557d329b..94781646b 100644 --- a/packages/vant-cli/src/compiler/gen-component-style.ts +++ b/packages/vant-cli/src/compiler/gen-component-style.ts @@ -2,7 +2,7 @@ * Build style entry of all components */ -import { join, relative } from 'path'; +import { sep, join, relative } from 'path'; import { outputFileSync } from 'fs-extra'; import { getComponents, replaceExt } from '../common'; import { CSS_LANG, getCssBaseFile } from '../common/css'; @@ -72,7 +72,7 @@ function genEntry(params: { } content += depsPath.map(template).join('\n'); - + content = content.replace(new RegExp('\\' + sep, 'g'), '/'); outputFileSync(outputFile, content); }); } 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 815bd69ef..102d130ad 100644 --- a/packages/vant-cli/src/compiler/gen-style-deps-map.ts +++ b/packages/vant-cli/src/compiler/gen-style-deps-map.ts @@ -1,4 +1,4 @@ -import { join } from 'path'; +import { relative, sep, join } from 'path'; import { CSS_LANG } from '../common/css'; import { existsSync } from 'fs-extra'; import { getDeps, clearDepsCache, fillExt } from './get-deps'; @@ -6,10 +6,9 @@ import { getComponents, smartOutputFile } from '../common'; import { SRC_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant'; function matchPath(path: string, component: string): boolean { - return path - .replace(SRC_DIR, '') - .split('/') - .includes(component); + const p = relative(SRC_DIR, path); + const arr = p.split(sep); + return arr.includes(component); } function getStylePath(component: string) {