Skip to content

Commit

Permalink
fix(mini-runner/mini-split-chunks): 分包的正则尾部添加/,避免出现类似subA和subA-B两个名字部…
Browse files Browse the repository at this point in the history
…分相同的分包能匹配到一个page
  • Loading branch information
huangcj99 committed Nov 26, 2020
1 parent eaeef67 commit cbdbd60
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/taro-mini-runner/src/plugins/MiniSplitChunksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin {
root: this.formatSubRoot(subPackage.root)
}))
this.subRoots = this.subPackages.map((subPackage: SubPackage) => subPackage.root)
this.subRootRegExps = this.subRoots.map((subRoot: string) => new RegExp(`^${subRoot}`))
this.subRootRegExps = this.subRoots.map((subRoot: string) => new RegExp(`^${subRoot}/`))
this.distPath = compiler?.options?.output?.path as string
this.isDevMode = compiler.options.mode === 'development'

Expand Down Expand Up @@ -149,7 +149,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin {
}

if (this.matchSubCommon(chunk)) {
let depName = chunkName.replace(new RegExp(`^${SUB_COMMON_DIR}/(.*)`), '$1')
const depName = chunkName.replace(new RegExp(`^${SUB_COMMON_DIR}/(.*)`), '$1')

if (this.subCommonDeps.has(depName)) {
existSubCommonDeps.set(depName, (this.subCommonDeps.get(depName) as DepInfo))
Expand All @@ -167,11 +167,11 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin {
compilation.chunkTemplate.hooks.renderWithEntry.tap(PLUGIN_NAME, (modules, chunk) => {
if (this.isSubChunk(chunk)) {
const chunkName = chunk.name
const chunkSubRoot = this.subRoots.find(subRoot => new RegExp(`^${subRoot}`).test(chunkName))
const chunkSubRoot = this.subRoots.find(subRoot => new RegExp(`^${subRoot}/`).test(chunkName))
const chunkAbsulutePath = path.resolve(this.distPath, chunkName)
const source = new ConcatSource()
const subVendors = this.subPackagesVendors.find(subPackagesVendor => {
return new RegExp(`^${chunkSubRoot}`).test(subPackagesVendor.name)
return new RegExp(`^${chunkSubRoot}/`).test(subPackagesVendor.name)
})
const subCommon = [...(this.chunkSubCommons.get(chunkName) || [])]

Expand Down Expand Up @@ -217,7 +217,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin {
const mapSourcePath = path.resolve(subCommonPath, depJsMapFileName)
const chunks = [...subCommonDep.chunks]
const needCopySubRoots: Set<string> = chunks.reduce((set: Set<any>, chunkName: string) => {
const subRoot = this.subRoots.find(subRoot => new RegExp(`^${subRoot}`).test(chunkName))
const subRoot = this.subRoots.find(subRoot => new RegExp(`^${subRoot}/`).test(chunkName))

set.add(subRoot)
return set
Expand Down Expand Up @@ -319,7 +319,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin {
* match sub-common\/*
*/
matchSubCommon(chunk: webpack.compilation.Chunk): boolean {
return new RegExp(`^${SUB_COMMON_DIR}`).test(chunk.name)
return new RegExp(`^${SUB_COMMON_DIR}/`).test(chunk.name)
}

/**
Expand Down Expand Up @@ -351,7 +351,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin {

chunkNames.forEach((chunkName: string) => {
this.subRoots.forEach((subRoot: string) => {
if (new RegExp(`^${subRoot}`).test(chunkName)) {
if (new RegExp(`^${subRoot}/`).test(chunkName)) {
chunkSubRoots.add(subRoot)
}
})
Expand All @@ -372,7 +372,7 @@ export default class MiniSplitChunksPlugin extends SplitChunksPlugin {
return false
}

return chunks.every((chunk) => (new RegExp(`^${subRoot}`)).test(chunk.name))
return chunks.every((chunk) => (new RegExp(`^${subRoot}/`)).test(chunk.name))
},
name: `${subRoot}/${SUB_VENDORS_NAME}`,
minChunks: 2,
Expand Down

0 comments on commit cbdbd60

Please sign in to comment.