Last time we talked about how to use NPM and some of the command line utilities that you can install that are built using Node.js. Today, we’re actually going to build a small command line utility ourselves that can be a bit of a time saver. We’re going to use the RequireJS optimizer to automatically concatenate and minify our CSS files the moment any of them are changed.
In the video I mention a tutorial done by Jeffrey Way. You can find that video on Youtube. There is a caveat to using the automatic minification described in this video: debugging via the inspector. If you’re using an inspector in the browser it’ll always tell you the style is in style.min.css on line 1, which makes it a lot more difficult to find the problematic rules and almost completely removes the benefits of having your styles in separate stylesheets.
If you want to learn more about using the RequireJS Optimizer or the fs.watchFile
function, use the links below. There’s also a link to the source code that I used.
- RequireJS Optimizer
- fs.watchFile
- GitHub Repository with source code used in video
Conclusion
There are tons of cool things that you can do with Node.js and just thinking about the fact that there’s a watchFile
method can inspire tons of ideas by itself. You can use web sockets to update an online file manager when someone else uses FTP to upload their own files. I hope you enjoyed this. God bless and happy coding!