Skip to content

Commit

Permalink
feat: 修复 引用路径问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ximing committed Aug 12, 2019
1 parent 6265f36 commit 696d839
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpbuild",
"version": "1.2.17",
"version": "1.2.18",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions src/plugin/handleWXMLDep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -18,7 +17,10 @@ const generateCode = function(ast, code = '', distDeps, asset) {
code += `<!-- ${data} -->`;
} 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) =>
Expand All @@ -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(
{
Expand Down Expand Up @@ -111,15 +113,15 @@ module.exports = class HandleWXMLDep {
}
}

distDeps.push(outputPath);
distDeps[src] = outputPath;
return mpb.assetManager.addAsset(filePath, outputPath, {
root,
source: asset.filePath
});
})
);

if (distDeps.length) {
if (Object.keys(distDeps).length) {
const ast = htmlparser.parseDOM(asset.contents, { xmlMode: true });
asset.contents = generateCode(ast, '', distDeps, asset);
}
Expand Down

0 comments on commit 696d839

Please sign in to comment.