His belief that clean, well-organized code is key to making software maintainable has led him to focus on unit testing and solid programming practices and principles as a cornerstone of everyday coding.
He is also the author of Require JS: Dependency Injection and Module Loading
Also in this series:
This episode takes a look at the 4th module of the course:
Using Transforms and Plugins
We see the Browserify processing pipeline:
Further details on the processing pipeline can be found here on Github.
Transforms apply early on this pipeline.
Transforms are a bit like loaders in webpack: you can use them to load CoffeeScript, TypeScript, ES6 code, plan text, HTML etc.
Plugins are more powerful than transforms and can change the entire way that Browserify processes files. They apply to every step in the above processing pipeline.
Hbsfy (Handlebarsify) Transform
Jeff explains the syntax highlighting and other benefits that Handlebarsify gives you.
He moves the inline template into the handlebars file task.hbs
Now we can run Browserify with -t hbspfy and see that the application still works.
Writing Custom Transforms
For much more information on streams in Node, see James Halliday’s stream handbook.
Jeff write the base transform handlebars-transform.js with three functions:
All this does so far is take the browserify contents and pass them back unchanged. Jeff explains each of these functions, and then builds on this foundation, adding handlebars as a dependency, and extending the processFile function to process .hbs files.
Next transform and flush are updated, and we run browserify with our new transform.
You probably won’t need to write your own Browserify plugin, and it’s best to first look at the plugins that are already available from NPM.
From the command line, we load plugins with the -p option.
James “substack” Halliday has written the browserify handbook. It is very popular with over 3000 Github stars. Here are the section that complement this module of the course: