Skip to content

Instantly share code, notes, and snippets.

@j8seangel
Last active February 4, 2017 11:53
Show Gist options
  • Save j8seangel/760caa9576e1f387785e648fd59ed87c to your computer and use it in GitHub Desktop.
Save j8seangel/760caa9576e1f387785e648fd59ed87c to your computer and use it in GitHub Desktop.
NPM as build tool

Add comments

 "//": "Comments here", (IN THE OBJECT CONFIG)
 # Comment here \n\t (INLINE SCRIPT)

Get the env, path or npm variables

npm run env
npm run env | grep "^PATH" 
npm run env | grep "npm_package" | less 

Running scripts

script1 && script2 (IN SERIES)
script1 & script2 (IN PARALLEL) 
& wait (NOT FINISH UNTIL CTRL + C)

RUN a bunch of task

npm-run-all task:* (optional --parallel flag)

Piping

Use | to get the result of the prev task Use > to get the result of the all processes and finish

Log level

-s SILENT 
-d VERBOSE
-dd MUCH VERBOSE
-ddd EXTREME VERBOSE

Cross env friendly

npm i cross-env cross-var -D to environment variables
npm i rimraf -D to remove folders
npm i opn-cli -D to open
And prefix conflicts with it

Windows doesn't support singlequote so scape double \"

Using scripts

  • Create a script.sh
  • Add #!/usr/bin/env bash in the first line
  • echo "What your script do.."
  • Write the scripts there
  • echo "What your script did.."
  • Add the reference in the package.json as "task": "./path/script.sh/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment