From 707110e77da6b8e97f3c9375101f934c17d3ecf5 Mon Sep 17 00:00:00 2001 From: ykforerlang <1527997464@qq.com> Date: Thu, 2 Jan 2020 11:20:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(alita):=20watch=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=EF=BC=8CwxComponent=20=E7=9B=AE=E5=BD=95=E7=9A=84=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configure.ts | 3 +++ src/entrytran/handleEntry.ts | 9 +++++++++ src/extractWxCompFiles/copyPackageWxComponents.ts | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/configure.ts b/src/configure.ts index 6fdd564..c105a88 100644 --- a/src/configure.ts +++ b/src/configure.ts @@ -42,6 +42,9 @@ interface IConfigure { // 小程序平台全局对象 mpGlobalObject: string + + // 由路由subpage属性生成 + allChunks?: any } const configure = { diff --git a/src/entrytran/handleEntry.ts b/src/entrytran/handleEntry.ts index 4a5cfd7..4e0ff5b 100644 --- a/src/entrytran/handleEntry.ts +++ b/src/entrytran/handleEntry.ts @@ -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 @@ -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++) { @@ -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}"`) @@ -594,6 +602,7 @@ function miscPageInfos(pageInfos, moduleMap) { pagePaths, historyMap, pageCompPaths, + allChunks, } } diff --git a/src/extractWxCompFiles/copyPackageWxComponents.ts b/src/extractWxCompFiles/copyPackageWxComponents.ts index 404aae3..cf58e98 100644 --- a/src/extractWxCompFiles/copyPackageWxComponents.ts +++ b/src/extractWxCompFiles/copyPackageWxComponents.ts @@ -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) + } + } + }) } @@ -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]}` @@ -88,5 +99,5 @@ function getRelativeChunks(moduleInfos, dirname) { } } - return Array.from(chunks) + return chunks } \ No newline at end of file