为什么

一般项目开发过程中,我们都要编写​​(CV)​​​一大堆重复性的代码,比如一个​​views/login/index.vue​​​比如​​store/modules/app.js​​这些文件都是重复毫无意义的,找一个自动生成的工具就很有价值了

使用

在​​github​​​上找到了这样一个包​​plop​​,具体信息可以自行去看官方文档,下面直接给出我在项目中使用的

可以看我的这个项目,里面有具体的​​demo​​​​fast_h5_vue​

1.项目根目录下新建​​plopfile.js​

const viewGenerator = require('./plop-templates/view/prompt')
const componentGenerator = require('./plop-templates/component/prompt')
const storeGenerator = require('./plop-templates/store/prompt.js')

module.exports = function(plop) {
plop.setGenerator('view', viewGenerator)
plop.setGenerator('component', componentGenerator)
plop.setGenerator('store', storeGenerator)
}

这里是三个文件类型分别是​​view​​​页面,​​component​​​组件,​​store vuex​​文件

2.项目根目录下新建​​plop-templates​​文件夹

代码太多,我直接给出文件链接​plop-templates​

3.新增脚本

在​​package.json​​中新增

"script":{
...,
"new":"plop"
}

4.具体使用

控制台直接输入命令

yarn new

按照提示选择文件类型

关于