Get Programmatic Control of your Builds with Netlify Build Plugins

Learn Development at Frontend Masters

Today at Jamstack_Conf, Netlify announced Build Plugins. What it does is allow you to have particular hooks for events within your build, like when the build starts or ends. What’s nice about them is that they’re just a plain ‘ol JavaScript object, so you can insert some logic or kick off a library just the way you typically would within your application.

A “Build” is when you give your site to Netlify either via GitHub/GitLab/etc., or by literally just dropping the directory into the interface, Netlify will process all the assets, download and install packages, and generate a static version of the site to deploy to CDNs all around the world.

What the Build Plugin does is give you access to key points in time during that process, for instance, onPreBuild, onPostBuild, onSuccess, and so forth. You can execute some logic at those specific points in time, like this:

module.exports = {
onPreBuild: () => {
console.log('Hello world from onPreBuild event!')
},
}

You don’t only have to build them yourself, either! You can use build plugins that have been made by the community. There are very interesting ones, such as a11y, Cypress for testing, Inline Critical CSS, and my personal favorite, Subfont, which optimizes fonts for you in a really incredible way (you can watch a video about that).

Enable them through the dashboard through a few button clicks:

https://i0.wp.com/css-tricks.com/wp-content/uploads/2020/05/image-22.png?fit=1024%2C836&ssl=1

If you’d like to learn more, check out the announcement post here! Happy building!

https://res.cloudinary.com/css-tricks/image/upload/f_auto,q_auto/v1578173278/FEM-sidebar-webpack_sprq2a.png