前语

咱们日常开发中常常需求新建目录和文件,但是这些东西是高度相同,而咱们却需求重复的进行。原始的做法则是运用全能的 Ctrl + cCtrl + v,来一个个手动创立,例如咱们在 VSCode 中开发微信小程序,每当咱们新建一个页面或许女配满眼都是钱一个微信小程序麻将辅助器组件的时分咱们都需求新建 **.wxml**.js**.wxss**.json 这样四个文件,然后再依据组件或许页面动态创立内部的变量和 class 名。这样严峻降低了咱们的开发功率,而 plop 东西就json文件是干什么的能很好的帮忙咱们处理这些繁琐而又简略的事情。

Plop 是什么?

Plop is what I like to call a “micro-generator framework.” Now, I call it that because it is a small tool that gives you a simNPMple way to generate code or any other type of flat text files in a consistent way. You see, we all create structures and patterns in our code (routes, controllers, components, helpers, etc). These patterns change and improve over time微信小程序怎样注册 so when you need to create a NE微信小程序怎样注册W insert-name-of-pattern-here女配明天见, it’s not always easy to男配每天都在体内成绩 loc微信小程序麻将胜率90ate the files in you微信小程序游戏r codebase that represent the current “bJSONest practice.” That’s where plop微信小程序游戏 saves you. With plop, yjson文件是干什么的ou have your “best practice” method of creatingjson格局怎样翻开 any given pattern in CODE. Code that can easily be run from the tjsonperminal by typing plop. Not only does this save you from hunt微信小程序怎样注册ing around in your codebase for the right file微信小程序怎样封闭s to copy, but it also turns “the right way” into “the easiest way” t女配没有求生欲o make new files.

这是 Plop 官网自json怎样读身的介绍,简略翻译过来就是:
Plop 是一个小型的构建结构,它能经过终女配没有求生欲txt端指令快速创立你所需求的模板文件。
官网地址:plopjs.cojson文件是干什么的m/,
一起你需求了解下 .hbs 这样的语法。json格局怎样翻开

运用

设备

运用 Plop 前,咱们需求设备 Plop

// 此处运用全局json解析设备
npm install -g plop

创立文件目录

然后咱们新建检验目微信小程序怎样制作自己的程序录,初始化 npm,而且创立 plopfile.js 文件,此文件为 Plop 的进口文件,类似 gulpfile.js

mkdir plop-demo
cd plop-demo
//女配每天都在抱大腿 此处一路回车就能够了
npm init

目录结构如下图:

plop简略实践

编写 plopfile.js 文件

// plopfile.js 文件
module.exports = plop => {
// 第女配明天见一个参数为 plop 子工程名,第二个参数为 plop 的装备参数
p女配没有求生欲藤萝为枝lop.setGenerator('component', {
// 工程描绘(女配没有求生欲此处创立vue模板为例)
description: 'Create a vue component',女配每天都在抱大腿我要成仙
// 终端交互,搜集用户输入JSON信息
prompts: [
{
type: 'input', /微信小程序怎样做店铺/女配每天都在抱大腿我要成仙 交互类型
name: 'name', // 当时交互的信息字段
message: 'Component name', // 提女配没有求生欲藤萝为枝示信息
default: 'my-component' // 默许称号
}
],
// plop 的履行
actions: [
{
type: 'add', // 方法(此为新建)
path: 'src/components/{{name}}/{{name}}.vue', // 生成文件的途径
templateFile: 'plop-templates/com微信小程序怎样注册ponents/vue.hbs' // plop 模板微信小程序麻将透明挂途径
}
]
})
}

编写 vue.hbs 模板

<template>
<div class="{{name}}">
{{name}}组件
</div>
</template>
<sc微信小程序麻将透明挂ript>
export def微信小程序怎样注册ault {
name: '{{name}}'
}
</script>
<style scoped>
.{{name}} {
background-女配没有求生欲txtcolor: #f5f6f7;
}
</style>

修改 package.json 文件,并运转

修改 package.json 文件,创微信小程序怎样封闭建快女配没有求生欲速构建指令

{
.女配每天都在为国争光..
scripts: {
"vueComponent": "plop component"
}
}

然后,在终端输入 npm run vueComponentjson格局怎样翻开 则能够快速创立 vue 的模板(此处只是举例说明,运用 vscode 的话直接创立 vscode 的代码片段更快json格局),你会开到终端提示如下:

plop简略实践

输入 Hejson文件是干什么的llo 组件名后,主动创立文件

plop简略实践

创立后 Hello.vuejson怎样读文件内容

plop简略实践

这样就能快速创立自己想要的文件和目录结构了。