赞
踩
vue项目中(基于vue-cli脚手架),新建模块时必然伴随新建vue文件夹、router文件、api文件,一阵复制粘贴噼里啪, low且繁琐。 本章探讨基于node实现一键生成模块seed(模板)文件。
我们的预期是执行node命令,生成以下文件
src > views > 模块文件夹 > index.vue + children文件夹 + commons文件夹
src > router > 模块文件
其中index.vue、router.js设置固定模板。
配置文件,设置需要生成的文件夹名、路径以及所需要的模板。
1 2 3 4 5 6 7 8 9 10 11 12 |
// pathConfig/index.js /** * @param {*} fileName * @param {*} filePath * @param {*} fileTemplate */ const dirAndPath = { router: ['router', './view.js'], views: ['views', './view.js'] }; module.exports = dirAndPath; |
模板文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。