preface
May often forget some commands, record the basic command standby their query, there is a new update, save often go to the network search
1. Basic operations
// Node installation usually comes with NPM to check whether the installation is successful
npm -v / / 6.14.6
npm i // Initialize the project // short for NPM install
npm i ${package} // Install project dependencies
npm i ${package} -g // Global installation
npm i ${package@2.0. 0} // Install the specified version
// NPM is too slow? Switch CNPM Taobao image
npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy the code
- Tips1: MAC bro added in front of NPM during global installation
sudo
- Tips2: Installation error, often exit in the middle of the installation and continue the installation error, this is due to cache.
npm cache clean --force
Copy the code
- Tips3: –save-dev and –save
Install to the development environment
npm i ${package} --save-dev
Or use the -d
package.json
的devDependencies
Inside is the project development environment needs to depend on.devDependencies
Represents modules required for project development
Install it in the production environment
npm i ${package} --save
Or use the -spackage.json
的dependencies
Inside are the dependencies needed for the project’s production run.dependencies
Represents the module on which the project runs
2. Dependence on addition, deletion and modification
- Upgrade depend on
npm update vue // Take vue as an example
Copy the code
- Delete rely on
npm uninstall vue // Take vue as an example
Copy the code
- Update all project dependencies
Install NPM install -g npm-check-updates or npm-check updates
ncu // View updatable dependencies under the project
Copy the code
3. Project operation and packaging
View scripts in package.json and run the command
// Take my VUE project for example
npm run serve // Run the project
npm run build // Package the project
Copy the code
More order please refer to the link docs.npmjs.com/cli/v8/comm…