preface

In the preparation of the conventional background management system, it is usually found that most pages have similar structure, basically by the head query box, the middle paging query table and pop-up box for adding or editing. As shown below:

idea

There are plenty of low-code generators that have done one-click generation for similar pages, but the overall experience is too large and not very good. Our most immediate needs are:

  1. Reduce copy and paste of code
  2. Simple to use, easy to use
  3. Size small
  4. Easy to modify and customize

So I came up with the idea of using a scaffolding tool to generate the corresponding files through templates and command-line queries. Common scaffolding tools include Yeoman, Plop, Grunt, gulp, Fis, etc. The specific advantages and disadvantages of these tools are not mentioned here. Plop scaffolding was chosen to generate VUE files. It has the same advantages as above: it is light and easy to use and easy to customize.

The use of the PLOP

1. Install to the project

npm install --save-dev plop
Copy the code

You can also select global installation for future use

npm install -g plop
Copy the code

2. Create a template file

Create the Plop-templates template folder in the root directory and create the template file, as shown in the following figure

At the end of.hbs is the template file. Here we take a look at the dialog.hbs introduction

3, create entry file plopfiles.js and put it in the root directory

4. Run plop

To facilitate NPM running, now configure plop in package.json, as shown in the figure below

Then execute on the terminal and a dialog box appears

npm run plop
Copy the code

The result is as follows

Then the corresponding file is generated, and finally the automatic generation of duplicate code is completed

conclusion

As a mini-generator, Plop can quickly and easily help us generate corresponding files, improve the efficiency of development, and make it easy to write templates.

Reference links: blog.csdn.net/hjb2722404/… Thanks for the reference