From 696d839b7b1fcf12c38d3645ca914b79e786a7f8 Mon Sep 17 00:00:00 2001 From: ximing Date: Mon, 12 Aug 2019 17:58:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=20=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/plugin/handleWXMLDep.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index c75da33..6e10e75 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mpbuild", - "version": "1.2.17", + "version": "1.2.18", "description": "", "main": "src/index.js", "scripts": { diff --git a/src/plugin/handleWXMLDep.js b/src/plugin/handleWXMLDep.js index 44fc4d5..8658aea 100644 --- a/src/plugin/handleWXMLDep.js +++ b/src/plugin/handleWXMLDep.js @@ -7,7 +7,6 @@ const fs = require('fs'); const resolve = require('resolve'); const generateCode = function(ast, code = '', distDeps, asset) { - let index = 0; const { length } = ast; for (let i = 0; i < length; i++) { const node = ast[i]; @@ -18,7 +17,10 @@ const generateCode = function(ast, code = '', distDeps, asset) { code += ``; } else { if (['include', 'wxs', 'import'].indexOf(name) >= 0 && attribs.src) { - attribs.src = path.relative(path.dirname(asset.outputFilePath), distDeps[index++]); + attribs.src = path.relative( + path.dirname(asset.outputFilePath), + distDeps[attribs.src] + ); } code += `<${name} ${Object.keys(attribs).reduce( (total, next) => @@ -45,7 +47,7 @@ module.exports = class HandleWXMLDep { if (/\.wxml$/.test(asset.name)) { try { const deps = []; - const distDeps = []; + const distDeps = {}; await new Promise((resolve, reject) => { const parser = new htmlparser.Parser( { @@ -111,7 +113,7 @@ module.exports = class HandleWXMLDep { } } - distDeps.push(outputPath); + distDeps[src] = outputPath; return mpb.assetManager.addAsset(filePath, outputPath, { root, source: asset.filePath @@ -119,7 +121,7 @@ module.exports = class HandleWXMLDep { }) ); - if (distDeps.length) { + if (Object.keys(distDeps).length) { const ast = htmlparser.parseDOM(asset.contents, { xmlMode: true }); asset.contents = generateCode(ast, '', distDeps, asset); }