ho 66: WeChat small program is a project, and build a house, and laid the foundation, in order to ensure that follow-up engineers built on a reliable and solid foundation. I need to constantly build new projects, each time I repeat "modify the structure of the project ->, copy and paste the file -> from the old project, delete some of the old project code" such a process, it really bother. How to efficiently write WeChat applets? Look at the Tencent engineers summed up this method,


another sore point is: every time a new small program page to generate three files with the same name (.Wxml,.Wxss and.Js), the command line is too long (according to WeChat colleagues: in app.json can also add a new page to the pages field under the path of preservation will generate the corresponding documents).


therefore, reading this article requires a little understanding of small program development (simple tutorial directions)


we have two goals now:

builds new project

based on the generic template

a key new page directory, and three files in the directory:.Wxml,.Wxss and.Js, you can also directly create a page in the app.json field of pages, save to generate the three files. I have no reason to adopt this method one is at the beginning don’t know this function, another is not the usual operating habits, and think of the JS file after the initialization, the need to introduce a common library, to insert code snippets, so keep this function.

these two requirements are very simple, and do not need GUI, so we can do a NPM command line tool. Imagine what this command line should look like:


uses a flow chart to illustrate:


implementation of


starts, please confirm the local development environment. The author’s local environment is:


, we split the problem into three steps:

implementation command line tool, you can run directly in any directory

performs different functions by typing different command line arguments to


consider the location of the project template, integrated into the tool, or separate from the tool


don’t worry. It’s easy to solve. We’ll see it one by one.

command line tool

There is one in

package.json >