Skip to content

Commit

Permalink
feat(build): 支持app.vue route添加文件类型筛选
Browse files Browse the repository at this point in the history
  • Loading branch information
JingyuanZhang committed Jun 4, 2019
1 parent 27fc6b7 commit 4161775
Showing 1 changed file with 12 additions and 1 deletion.
Expand Up @@ -12,6 +12,11 @@ function toCamel(name) {
return camelName.substring(0, 1).toUpperCase() + camelName.substring(1);
}

const routeExtraType = {
swan: '.swan',
wx: '.wxml'
};

module.exports = function getVisitor(options = {}) {
return ({types: t}) => {
const {
Expand All @@ -27,6 +32,9 @@ module.exports = function getVisitor(options = {}) {
let routesArr = [];
// import routes
for (let r of routes) {
if (r.indexOf(routeExtraType.wx) > -1 || r.indexOf(routeExtraType.swan) > -1) {
continue;
}
routesArr.push(t.objectExpression([
t.objectProperty(
t.identifier('path'),
Expand Down Expand Up @@ -72,6 +80,9 @@ module.exports = function getVisitor(options = {}) {

// import routes
for (let r of routes) {
if (r.indexOf(routeExtraType.wx) > -1 || r.indexOf(routeExtraType.swan) > -1) {
continue;
}
insertImportDeclaration(toCamel(r), `./${r}.vue`);
}

Expand All @@ -80,4 +91,4 @@ module.exports = function getVisitor(options = {}) {
}
};
};
}
};

0 comments on commit 4161775

Please sign in to comment.