1. plop
1.1 安装
javascript
yarn add plop -D
1.2 使用
1.2.1 package.json 配置脚本命令
javascript
"scripts": {
"dev": "vite --mode dev",
"build": "vue-tsc --noEmit && vite build",
"serve": "vite preview",
"p": "plop"
},
1.2.2 在主目录新建文件 plopfile.js
javascript
module.exports = function (plop) {
plop.setGenerator('view', {
description: '创建模块vue模板',
prompts: [
{
type: 'input',
name: 'path',
message: '请输入路径',
default: 'views'
},
{
type: 'input',
name: 'name',
message: '请输入模块名称'
}
],
actions: (data) => {
const { name, path } = data
const upperFirstName = toUpperCase(name)
const actions = []
if (name) {
actions.push({
type: 'add',
path: `./src/${path}/${upperFirstName}.vue`,
templateFile: './plop/view/view.hbs',
data: {
name,
upperFirstName
}
})
}
return actions
}
})
}