Skip to main content

Configuring webpack

For app developers, additional [webpack configuration] should not be needed as the most common setups are preconfigured for Gasket apps. However, there are a couple of integration points for apps and plugins should the need arise.

With the Gasket Webpack plugin installed, you can use the webpackConfig lifecycle and/or the nextConfig lifecycle or property for Gasket Next.js apps.


Apps can also use lifecycle files to hook the webpackConfig lifecycle to provide additional custom config. The hook function should return the updated Webpack config object.

You can utilize webpack-merge in your lifecycle hook, which is the recommended approach. While the webpackConfig object can be directly mutated, this can be brittle, so handle with care. Also, the webpack instance is passed via context with the lifecycle, providing access to the compatible Webpack plugins of the version installed.

Via lifecycle files

// lifecycles/webpack-config.js
const webpackMerge = require('webpack-merge');

module.exports = function (gasket, webpackConfig) {
return webpackMerge.merge(webpackConfig,
resolve: {
alias: {
'fancy-module': './path/to/some/other/module'

Via plugin hooks

// gasket-plugin-example.js
const externalPlugin = require('some-external-plugin-installed');
const anotherExternalPlugin = require('i-love-webpack');

module.exports = {
name: 'example',
hooks: {
webpackConfig(gasket, webpackConfig, { webpack }) {
return {
plugins: [
...(webpackConfig.plugins || []),
new webpack.EnvironmentPlugin([
new externalPlugin(),
new anotherExternalPlugin()


For Gasket Next.js apps you can use the same webpackConfig lifecycle. However, you may want to modify Webpack config using Next.js plugins or the Next.js custom Webpack approach, in which case the nextConfig lifecycle or the gasket.config.nextConfig property be helpful.

Via config property

// gasket.config.js
const withPreact = require('next-plugin-preact');

module.exports = {
nextConfig: withPreact({
/* regular next.js config options here */