Here is an example adding an additional global variable via the DefinePlugin and the less-loader: Absolute imports Sass, TypeScript, Glamor, and many more! Examples There are many plugins in the Gatsby repo using this API to look to for examples e.g. build-html: production build static HTML pages.Creates route JavaScript bundles as well as common chunks for JavaScript and CSS.
Gatsby does multiple webpack builds with somewhat different configuration. When Gatsby creates its webpack config, this function will be called allowing you to modify the default webpack config using webpack-merge. Inside this file, export a function called onCreateWebpackConfig. To add custom webpack configurations, create (if there’s not one already) a gatsby-node.js file in your root directory. If there’s not yet one and your use case is a general one, consider contributing your plugin to the Gatsby Plugin Library so it’s available to others (including your future self). Before creating custom webpack configuration, check to see if there’s a Gatsby plugin already built that handles your use case in the plugins section.