“This is the 18th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

preface

Sometimes, we don’t need to create a complete project structure, maybe we just need to create certain types of files on a project basis, for example:

  • We create certain types of base files from an existing project: Eslint, Babel, etc

It might be a bit of a problem to configure these configurations directly, so we can use the methods provided by Yeoman to do some of these configurations

Sub Generator

Here we can do some configuration using the CLI provided with generator-Node

Command:

yo node:cli
Copy the code

After entering the command, we select Yes

After that, we’ll create a lib folder +package.json

The file structure is as follows

Let’s go back to the file

We found that package.json already has the configuration

{
  "bin": "lib/cli.js"."dependencies": {
    "meow": "^ 3.7.0"
  },
  "devDependencies": {
    "lec": "^" 1.0.1
  },
  "scripts": {
    "prepare": "lec lib/cli.js -c LF"}}Copy the code

With this we can use these global modules

General procedure

  1. Identify your needs
  2. Find the right oneGenerator
  3. Global scope installation foundGenerator
  4. throughyoRun the correspondingGenerator
  5. Enter options through the command line interactively
  6. Generate the project structure you need

For example

  1. We are going to create a web application:
  2. So let’s go in hereYEOMANWebsite:YEOMAN
  3. searchweb app
  4. Installation:npm install --global yo gulp-cli generator-webapp
  5. Once installed, we can go throughYEOMANRun theyo webapp
  6. After that, some options will appear, such as whether you want to use Sass or not, and you can make some choices based on what you want to use
  7. Finally, we have the basic structure of a Web project

A digression

Here are some things to note: Using the generator project, his generator is dependent on some c + + module, these modules need to be at the time of installation need to download some binary files, it will lead to our installation is slow, but if you have a good result of NPM, you should know that we can go to set up some corresponding mirror to accelerate, Here we provide some configuration files