From d515db755ad7aa5d90ef8b370677246a17f410a1 Mon Sep 17 00:00:00 2001 From: huangcj99 Date: Thu, 10 Jun 2021 21:12:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(mini-runner):=20=E4=BF=AE=E5=A4=8Dwindow?= =?UTF-8?q?=E4=B8=8A=E6=9E=84=E5=BB=BA=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#9422)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/MiniSplitChunksPlugin.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/taro-mini-runner/src/plugins/MiniSplitChunksPlugin.ts b/packages/taro-mini-runner/src/plugins/MiniSplitChunksPlugin.ts index 211db8ed10c9..1c543ebaeb40 100644 --- a/packages/taro-mini-runner/src/plugins/MiniSplitChunksPlugin.ts +++ b/packages/taro-mini-runner/src/plugins/MiniSplitChunksPlugin.ts @@ -231,7 +231,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin { const subVendorsWxssPath = path.join(subRoot, `${SUB_VENDORS_NAME}${FileExtsMap.STYLE}`) const source = new ConcatSource() - if (assets[subVendorsWxssPath]) { + if (assets[this.formatSystemPath(subVendorsWxssPath)]) { const subVendorsAbsolutePath = path.resolve(this.distPath, subVendorsWxssPath) const relativePath = this.getRealRelativePath(wxssAbsulutePath, subVendorsAbsolutePath) @@ -243,7 +243,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin { const wxssFileName = `${moduleName}${FileExtsMap.STYLE}` const wxssFilePath = path.join(SUB_COMMON_DIR, wxssFileName) - if (assets[wxssFilePath]) { + if (assets[this.formatSystemPath(wxssFilePath)]) { const moduleAbsulutePath = path.resolve(this.distPath, subRoot, SUB_COMMON_DIR, wxssFileName) const relativePath = this.getRealRelativePath(wxssAbsulutePath, moduleAbsulutePath) @@ -375,7 +375,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin { * match *\/sub-vendors */ matchSubVendors (chunk: webpack.compilation.Chunk): boolean { - const subVendorsRegExps = this.subRoots.map(subRoot => new RegExp(`^${path.join(subRoot, SUB_VENDORS_NAME)}$`)) + const subVendorsRegExps = this.subRoots.map(subRoot => new RegExp(`^${this.formatSystemPath(path.join(subRoot, SUB_VENDORS_NAME))}$`)) const isSubVendors = subVendorsRegExps.find(subVendorsRegExp => subVendorsRegExp.test(chunk.name)) return !!isSubVendors @@ -440,7 +440,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin { return chunks.every(chunk => new RegExp(`^${subRoot}\\/`).test(chunk.name)) }, - name: path.join(subRoot, SUB_VENDORS_NAME), + name: this.formatSystemPath(path.join(subRoot, SUB_VENDORS_NAME)), minChunks: 2, priority: 10000 } @@ -455,7 +455,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin { const subCommonCacheGroup = {} this.subCommonDeps.forEach((depInfo: DepInfo, depName: string) => { - const cacheGroupName = path.join(SUB_COMMON_DIR, depName) + const cacheGroupName = this.formatSystemPath(path.join(SUB_COMMON_DIR, depName)) subCommonCacheGroup[cacheGroupName] = { name: cacheGroupName, @@ -518,4 +518,11 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin { getRealRelativePath (from: string, to: string): string { return promoteRelativePath(path.relative(from, to)) } + + /** + * 将window系统下的路径分隔符转成/ + */ + formatSystemPath (p) { + return p.replace(/\\/g, '/') + } }