As a JavaScript
developer, NPM
it 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 npm
jump 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 github
problem 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 CLI
The default command will only be based on package.json
specified semver
update packages that range.
npm update
But I think we do not believe the package author or we want to change their own semver
indicators. yarn
And provides interactive upgrade - the latest good enough utilities, but does not apply NPM
.
To NPM
clone this feature, you can use the name npm-check
of 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.
http://www.ruanyifeng.com/blog/2019/02/npx.html
$ npm install -g npx
6, faster installation in CI npm
npm install
It comes with some restrictions (user-oriented features), so that it inherently slow. But we are clearly CI
needed on these servers, NPM
allowing us to use these commands to skip.
npm ci
You can CI
in the server npm install
replaced npm ci
, if you package-lock.json
can 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 publish
Well, it can be used semver
to 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), NPM
it introduces a number of new automatic link.
"scripts": {
"prepublishOnly": "npm test"
}
Alternatively, the package np
better.
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 Github
released 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