Live data from Hacker News

Why I Left Gulp and Grunt for Npm Scripts

medium.com

11–20 of 75 posts

Re: Why I Left Gulp and Grunt for Npm Scripts

#11

Most of the issues with Grunt and the like can be done away with by following good coding practices. i.e. keep your code outside the Grunt context and write unit tests for it. See the Thin Grunt Manifesto: https://www.exratione.com/2015/08/thin-grunt-manifesto/ I'm not sure I buy fleeing to the command line as a viable alternative. You are in essence going to have to write a bash script at some point because the comm…

> You are in essence going to have to write a bash script at some point because the command will bloat beyond what can be sanely contained in a JSON property.

or do it in python like I did - http://kopy.io/yvEGl it works amazingly and gives you endless flexibility without require bash.

Re: Why I Left Gulp and Grunt for Npm Scripts

#12
post #2

Why don't they provide a good working example, using Browser Sync or LiveReload, Sass, etc ? I haven't found a good build process using npm as a task manager or build tool; I haven't seen any good example on any article I've read so far; gulp was built for, and it's much clear in my opinion!

If you're doing front-end development

Use JSPM for module management, transpiling (Babel, Traceur, Typescript), and bundling

live-server for LiveReload. With zero config it injects the LR stub and sets up a file watcher on the directory it's run in.

BrowserSync can be loaded via a npm command: https://gist.github.com/addyosmani/9f10c555e32a8d06ddb0

SASS can be setup with: https://medium.com/@brianhan/watch-compile-your-sass-with-np...

Here's what I use to build my Angular2+ES6 app: https://github.com/evanplaice/evanplaice.com/blob/master/pac...

Using npm as the default task runner is becoming more common so it's not to difficult to find good examples thru Google.

Re: Why I Left Gulp and Grunt for Npm Scripts

#13
post #6

I'm moving in a similar direction for similar reasons - but by shifting functionality out of the node ecosystem altogether. I recently released devd, a small, dev-focused HTTP server with build-in livereload which has taken the place of gulp livereload and node-based dev servers for many of my projects ( https://github.com/cortesi/devd ). I'm now working on the next step. It's not quite ready to be announced yet, but…

Why create devd when you could have just used live-server? It automatically injects the LiveReload stub and watches the directory for changes. I guess, if your end goal is to move everything away from the node ecosystem. To each their own.

Well, first, I think it's perfectly fine to have multiple takes on the same problem space. This is how we progress - people try different things, and we gradually figure out what works. Live-server does a specific set of things, and devd is a different take on a slightly wider set of things, and I think that's just dandy. The overlap is far from precise, and I think there's enough room for both devd and live-server (and for the many other tools that do similar things).

Second, not everything is node. Devd has lots of uses outside of node and even outside of front-end development.

Third, I probably wouldn't have written it if I didn't believe that devd did at least some things better than the current tools (at least for some people). You should try it - maybe you'll like it, and if you don't then that's fine too. As you say - to each their own. ;)

Re: Why I Left Gulp and Grunt for Npm Scripts

#14

I went the other way as well and used Python with Envoy to call every thing from the command line. It's quick, easy to debug (arguments to commands can be dumped in debug mode, run manually etc). Also for certain tasks Python annihilates Gulp plugins. This is a production example (not pretty code per se) http://kopy.io/yvEGl when combined with intellij watchers this makes it very easy to rebuild on change.

It adds yet another dependency just to get a project to initialize though which is a small negative. I guess npm needs python anyway for node-gyp but then you have to stick to python 2.

Re: Why I Left Gulp and Grunt for Npm Scripts

#15

I went the other way as well and used Python with Envoy to call every thing from the command line. It's quick, easy to debug (arguments to commands can be dumped in debug mode, run manually etc). Also for certain tasks Python annihilates Gulp plugins. This is a production example (not pretty code per se) http://kopy.io/yvEGl when combined with intellij watchers this makes it very easy to rebuild on change.

It adds yet another dependency just to get a project to initialize though which is a small negative. I guess npm needs python anyway for node-gyp but then you have to stick to python 2.

I deploy dev environments via vagrant/ansible so that's a slight upfront cost but something I never have to touch.

Using virtualenvs I can also keep one project isolated from another in terms of jumping around the filesystem.

The convenience is a major win and since I use python for everything other than the web framework which is PHP it actually ties together nicely.

Unconventional but it works really well.

Re: Why I Left Gulp and Grunt for Npm Scripts

#16
I'm glad to see more people following this approach.

The real consequence of having the community diverging on build tools is the added work required by tool creators to support them. I created a tool that included a grunt wrapper just before gulp became the new 'hottness' and quickly became fed up with the whole mess.

Soon after, I discovered that npm scripts can call the bin scripts of locally installed dependencies. I haven't looked back since.

NPM scripts make composing tasks nice... and there's nothing stopping you from adding custom configs to the package.json object.

Re: Why I Left Gulp and Grunt for Npm Scripts

#17
post #2

Why don't they provide a good working example, using Browser Sync or LiveReload, Sass, etc ? I haven't found a good build process using npm as a task manager or build tool; I haven't seen any good example on any article I've read so far; gulp was built for, and it's much clear in my opinion!

Personally I ended up with a mix.

Leave Gulp to be gulp and do the heavy lifting while using npm scripts to run the gulp tasks and anything that doesn't live inside gulp.

It gives the simplicity of allowing people unfamiliar able to look at the package.json file and no further if they just want to use it, and allows all the "plug and play" style plugins from gulp.

Re: Why I Left Gulp and Grunt for Npm Scripts

#18
This. A thousand times this. Embrace the unix philosophy of small tools and npm scripts and watch your baroque frontend build process with all its plugin dependencies reduce to amazing simplicity. Here's another good write up with some significantly more useful examples:

http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool...

> Package.json also doesn’t support variables

Not sure what he means by this, npm scripts do support env vars from package.json config values:

https://docs.npmjs.com/misc/scripts#configuration

Re: Why I Left Gulp and Grunt for Npm Scripts

#20
I am using npm scripts for everything too. Check out my article "tiny npm package": http://g14n.info/2015/12/tiny-npm-package/

Checkout my postversion hook!

By the way, even if JSON does not support comments, sometimes I add a "#TODO:fooscript" prop in the scripts, and add comments as well.

Another interesting trick is that a script can call other npm scripts.

Also another nice feature is that command in node_modules/.bin folder are added to PATH.

Yes, npm scripts rock!

Post reply on HN