Monday, 16 November 2015

Using NPM as a Task Runner.

In our website we may have some commands that we need to use over and over again.  Let’s say for example that we want to uglify a JS file .  We can write a command for that like . 

‘node_modules/.bin/uglifyjs src/models/* src/frontend.js -m -c -o build/app.js’  

I can then add this to the scripts object in the package.json  

“scripts”: {
“uglify”: “uglifyjs src/models/* src/front.js -m -c -o build/app.js"

Tip: you can run files sequentially with ‘&&’ or the same time with ‘&’


“build”: “npm run copy-files && npm run uglify"

No comments: