Skip to content

Commit b283134

Browse files
committed
feat: update Bolt build config to add support for extending / modifying the default Webpack config generated
1 parent 30872db commit b283134

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/build-tools/create-webpack-config.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const resolve = require('resolve');
1313
const CopyWebpackPlugin = require('copy-webpack-plugin');
1414
const WriteFilePlugin = require('write-file-webpack-plugin');
1515
const npmSass = require('npm-sass');
16+
const merge = require('webpack-merge');
1617
const SassDocPlugin = require('@bolt/sassdoc-webpack-plugin');
1718
const { getConfig } = require('./utils/config-store');
1819
const { boltWebpackProgress } = require('./utils/webpack-helpers');
@@ -237,7 +238,7 @@ async function createWebpackConfig(buildConfig) {
237238
},
238239
];
239240

240-
const webpackConfig = {
241+
let webpackConfig = {
241242
target: 'web',
242243
entry: await buildWebpackEntry(),
243244
output: {
@@ -497,6 +498,23 @@ async function createWebpackConfig(buildConfig) {
497498
};
498499
}
499500

501+
// Simple Configuration
502+
// The easiest way to tweak the Bolt webpack config is by providing an object to the configureWebpack option in the `.boltrc.js` config:
503+
504+
// // .boltrc.js
505+
// module.exports = {
506+
// configureWebpack: {
507+
// plugins: [
508+
// new MyAwesomeWebpackPlugin()
509+
// ]
510+
// }
511+
// }
512+
// The object will be merged into the final webpack config using webpack-merge.
513+
514+
if (config.configureWebpack) {
515+
webpackConfig = merge(webpackConfig, config.configureWebpack);
516+
}
517+
500518
return webpackConfig;
501519
}
502520

packages/build-tools/utils/config.schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@
225225
- none
226226
- console
227227
- cli
228+
configureWebpack:
229+
type: object
230+
description: 'Passing in an object will merge any config customizations with the default Bolt Webpack config (via <a href="https://github.com/survivejs/webpack-merge" target="_blank">webpack-merge</a>).'
228231
configFileUsed:
229232
type: string
230233
description: The filepath to the `.boltrc` file used to load config. Programatically added to config.

0 commit comments

Comments
 (0)