Whether or not you think it's a good idea to run your scripts using npm, I think you need to know how the process works. A lot of node packages are configured using npm scripts and so it's essential that you have experience with how the process work.
- So, let's take a look at why you should learn about npm scripts, and how to use them to create your tooling process. Build tools like npm scripts, Gulp.js, and Grunt allow you to automate common tasks that you need to do when working with modern web projects. So for example, you might want to run a server so that AJAX tasks work properly. Also so that you can see any changes to your documents as you're working with them. You may also want to process CSS languages like Less, Sass, or PostCSS so that they get compiled to CSS automatically and refresh your browser.
These scripts are configured using the package, that json file, that you already have to use when working with node.js. Therefore configuration is going to be simpler and a bit resistant to bloat. Your npm script tasks are always going to be smaller than any similar Gulp or Grunt process. Now because most Gulp and Grunt scripts are going to be wrappers to existing node packages, using npm as a build tool will allow you to run with the latest packages without having to wait for someone to build or update a wrapper for Gulp or Grunt.
Now, there are some issues with npm scripts that you should be aware of. First is that in a cross-platform environment, npm scripts are a little bit harder to set up, although Windows is adding Bash terminal support in Windows 10, not everyone will have updated to that operating system, and some commands, like ampersands for running parallel tasks, or things like the mkdir command, will not work on Windows. It's easy enough to work around those issues. So I'll show you how to work with that in this course.
The other problem is that having one quarter of a million npm packages doesn't mean that all those packages are gonna implement features consistently, so you may have to specify a source map option in one package and another package will call it source maps with an S at the end. The way to specify input and output is often different between different packages. Gulp tends to make that a lot more consistent. Npm scripts use adjacent object as a configuration file, which means that it's almost impossible to implement variables.
- Creating an npm script
- Managing script types
- Processing Sass
- Transpiling ES6
- Organizing scripts
- Recompressing for production