Skip to content

Commit 17b83d2

Browse files
authored
Merge pull request #2660 from dev-itsheng/2020-07-19-support-json-include
增加对 json 文件格式的支持。
2 parents df45e21 + 2fd8e77 commit 17b83d2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

packages/cli/core/plugins/parser/script.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const npmTraverseFileMap = {};
2020

2121
exports = module.exports = function() {
2222
this.register('wepy-parser-dep', function(node, ctx, dep) {
23+
const file = dep.module;
24+
if (file.endsWith('.json')) {
25+
return Promise.resolve(fs.readFileSync(path.resolve(path.dirname(ctx.file), file), 'utf8'));
26+
}
2327
return this.resolvers.normal.resolve({ issuer: ctx.file }, path.dirname(ctx.file), dep.module, {}).then(rst => {
2428
let npm = rst.meta.descriptionFileRoot !== this.context;
2529

packages/cli/core/plugins/scriptDepFix.js

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ exports = module.exports = function() {
2121
parsed.parser.deps.forEach((dep, i) => {
2222
if (!parsed.fixedDeps[i]) {
2323
let depMod = parsed.depModules[i];
24+
if (typeof depMod === 'string') {
25+
parsed.source.replace(dep.expr.start, dep.expr.end - 1, depMod);
26+
parsed.fixedDeps[i] = true;
27+
return;
28+
}
2429
if (typeof depMod === 'number') {
2530
depMod = this.vendors.data(depMod);
2631
}

0 commit comments

Comments
 (0)