This seven npm command will help you save time

As a JavaScriptdeveloper, NPMit is something we have been using, and our script to run continuously in the terminal.

If we can save some time?

1, open documents directly from npm

If we can directly npmjump to the document package how to do?

npm home package-name
# 例如:
npm home react  # 将在浏览器中打开reactjs.org

2, open the bug page

As a precaution, we would like to submit an error on the package.

npm bugs package-name
# 例如:
npm bugs @agney/playground

If the author of this package links will open in a browser githubproblem page (or any page in question).

3, see the package all the scripts

If you do not start to write, it is hard to remember the name of the script. You can run the following command to see the name of the script and running command, rather than go to package.json.

npm run

4, skipping all initialization problem

When you run npm init, it will ask a lot of questions, you can set an item, but it is best to skip most of the time and accept the default settings.

npm init -yes

5, the package will be updated to the latest version.

NPM CLIThe default command will only be based on package.jsonspecified semverupdate packages that range.

npm update

But I think we do not believe the package author or we want to change their own semverindicators. yarnAnd provides interactive upgrade - the latest good enough utilities, but does not apply NPM.

To NPMclone this feature, you can use the name npm-checkof the package.

npx npm-check --update

npx Node is built npm module, it can be used npx commands directly. In case can not be used, it is necessary to manually install it.

$ npm install -g npx

http://www.ruanyifeng.com/blog/2019/02/npx.html

6, faster installation in CI npm

npm installIt comes with some restrictions (user-oriented features), so that it inherently slow. But we are clearly CIneeded on these servers, NPMallowing us to use these commands to skip.

npm ci

You can CIin the server npm installreplaced npm ci, if you package-lock.jsoncan do well.

For example, continuous integration service  Travis CI configuration should be:

# .travis.yml
install:
- npm ci
# 保留npm缓存以加快安装速度
cache:
  directories:
  - "$HOME/.npm"

7, better npm release

npm publishWell, it can be used semverto update your version of the package, then the package will be pushed to the registry.

But it does omit some important steps: Build and test packages. To automatically perform these operations, you can use pre-release script.

"scripts": {
    "prepublish": "npm run build"
}

However, pre-release executed each time the installation, so instead of creating a change log or run a test of the best location. After the names put forward some criticism (in any case this is the most difficult thing), NPMit introduces a number of new automatic link.

"scripts": {
    "prepublishOnly": "npm test"
}

Alternatively, the package npbetter.

You can simply run:

npx np

It will run all the necessary steps, including installation packages, build and run the test. It will also create a label and Githubreleased on.

You can also use any tricks to save time? You can share in the comments.

Original: https://xushanxiang.com/2019/12/7-npm-commands-to-save-time.html

Guess you like

Origin www.cnblogs.com/xusx2014/p/11986276.html
Recommended