Skip to content

Commit

Permalink
feat(alita): watch模式下,wxComponent 目录的删除
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Jan 2, 2020
1 parent 8b23d81 commit 707110e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ interface IConfigure {

// 小程序平台全局对象
mpGlobalObject: string

// 由路由subpage属性生成
allChunks?: any
}

const configure = {
Expand Down
9 changes: 9 additions & 0 deletions src/entrytran/handleEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,11 @@ export default function (ast, filepath, webpackContext) {
subpackages,
removeModules,
ensureStatements,
allChunks
} = miscPageInfos(pageInfos, moduleMap)

configure.allChunks = allChunks

appJSON.pages = pages
if (subpackages.length > 0) {
appJSON.subpackages = subpackages
Expand Down Expand Up @@ -509,6 +512,8 @@ function miscPageInfos(pageInfos, moduleMap) {
const historyMap = {}
const pageCompPaths = []

const allChunks = ['_rn_']

const removeModules = new Set()

for (let i = 0; i < pageInfos.length; i++) {
Expand Down Expand Up @@ -544,6 +549,9 @@ function miscPageInfos(pageInfos, moduleMap) {
const allSubPages = Object.keys(subpages)
for(let i = 0; i < allSubPages.length; i ++ ) {
const subpage = allSubPages[i]

allChunks.push(`${subpage}/_rn_`)

const allComps = subpages[subpage]

const depsStr = allComps.map(comp => `"${moduleMap[comp].source}"`)
Expand Down Expand Up @@ -594,6 +602,7 @@ function miscPageInfos(pageInfos, moduleMap) {
pagePaths,
historyMap,
pageCompPaths,
allChunks,
}
}

15 changes: 13 additions & 2 deletions src/extractWxCompFiles/copyPackageWxComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export default function () {
fse.copySync(sourcePath, targetPath)
}
})

configure.allChunks.forEach(chunk => {
if (!chunks.has(chunk)) {
const chunkDic = chunk === '_rn_' ? '' : chunk.replace('/_rn_', '')
const targetDic = path.resolve(configure.outputFullpath, chunkDic, 'npm', packageInfo.aliasPackName)

if (fse.existsSync(targetDic)) {
fse.removeSync(targetDic)
}
}
})
}


Expand Down Expand Up @@ -65,7 +76,7 @@ export function getCompPath(chunk, packageName, element) {

if (pathMap[element]) {

if (chunks.length === 1 && chunks[0] === '_rn_') {
if (chunks.size === 1 && chunks.has('_rn_')) {
return pathMap[element]
} else {
return `/${chunk.replace('/_rn_', '')}${pathMap[element]}`
Expand All @@ -88,5 +99,5 @@ function getRelativeChunks(moduleInfos, dirname) {
}
}

return Array.from(chunks)
return chunks
}

0 comments on commit 707110e

Please sign in to comment.