Last active
November 17, 2017 14:27
-
-
Save tlareg/55e278fad5e46290ef03 to your computer and use it in GitHub Desktop.
npm_scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create package.json | |
npm init | |
# can define scripts in package.json | |
# pre and post runs before and after script | |
"scripts": { | |
"pretest": "echo 'running pretest'", | |
"test": "echo 'no test specified'", | |
"posttest": "echo 'running posttest'", | |
"start": "echo 'running start script'", | |
"dupa:dd": "npm run start", | |
"compile:first": "", | |
"compile:second": "", | |
"compile": "npm run compile:first && npm run compile:second", | |
"build-js": "browserify client/entry.coffee | uglifyjs -mc > public/main.js" | |
} | |
# run scripts | |
npm run <script_name> | |
# list available npm scripts | |
npm run | |
# shorthand for running script called "start" | |
npm start | |
# another shorthands | |
npm stop | |
npm restart # if restart not defined runs stop and start | |
# avaliable commands listed under node_modules/.bin | |
# install packages | |
npm install --save-dev | |
npm i -D | |
npm install --save | |
npm i -S | |
# link - npm run-scripts boilerplate | |
https://gist.github.com/addyosmani/9f10c555e32a8d06ddb0 | |
# "&&" - chaining commands, "|" - piping output, ">" - write output to file | |
# "&" - run concurrently (on linux), "START /B" on windows | |
# "-- " - pass through args eg. | |
npm test -- -w | |
# save installation log to log.txt, ddd is for logLevel silly - usefull for debuging | |
npm i -ddd 2>&1 | tee log.txt | |
# search package_name in dependencies tree | |
npm ls <package_name> | |
# usefull when running many scripts in one command | |
https://github.com/mysticatea/npm-run-all | |
# watch files | |
https://github.com/Qard/onchange | |
onchange 'app/**/*.js' 'test/**/*.js' -v -- npm test | |
# search env variables | |
$ npm run env | grep npm_package_version* | |
npm_package_version=2.2.0 | |
# easy git hooks | |
https://github.com/typicode/husky | |
# for windows | |
https://github.com/kentcdodds/cross-env | |
https://github.com/elijahmanor/cross-var | |
https://github.com/isaacs/rimraf | |
https://github.com/sindresorhus/opn-cli | |
# npm task list | |
https://github.com/ruyadorno/ntl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment