为什么我们在一般的项目开发过程中要写(CV)很多重复的代码,比如一个views/login/index.vue比如store/modules/app。js文件是重复的,没有意义的。找到一个自动生成的工具是非常有价值的。我在github上找到了这样一个包plop。具体的可以自行去看官方文档。下面直接给出我在项目中使用的那个。你可以看到我的项目,其中包含具体的demofast_h5_vue1。创建一个新的plopfile.jsconstviewGenerator=require('./plop-templates/view/prompt')constcomponentGenerator=require('./plop-templates/component/prompt')conststoreGenerator=require('./plop-templates/store/prompt.js')module.exports=function(plop){plop.setGenerator('view',viewGenerator)plop.setGenerator('component',componentGenerator)plop.setGenerator('store',storeGenerator)}这里是三种文件类型:viewpage,component组件,storevuex文件2.项目根目录下新建的plop-templates文件夹里面代码太多,我直接给文件链接plop-templates3.添加脚本添加》script"inpackage.json:{...,"new":"plop"}4.具体使用控制台直接输入命令yarnnew按照提示选择文件类型AboutFile代码:https://github.com/ahwgs/fast_h5_vue文章首发于:使用plop自动新建工程文件
