digitalbazaar / bedrock-webpack

Bedrock webpack module.
Apache License 2.0
0 stars 2 forks source link

Add Config Section for default plugins #51

Open aljones15 opened 1 year ago

aljones15 commented 1 year ago

Currently we have 8 default plugins:

https://github.com/digitalbazaar/bedrock-webpack/blob/5d4834f620392f7bcb6c27710b2b38d79c7e1a30/lib/index.js#L393-L400

https://github.com/digitalbazaar/bedrock-webpack/blob/5d4834f620392f7bcb6c27710b2b38d79c7e1a30/lib/index.js#L460

https://github.com/digitalbazaar/bedrock-webpack/blob/5d4834f620392f7bcb6c27710b2b38d79c7e1a30/lib/index.js#L483-L487

the proposal is to create a new section in this library's config file which exposes the settings for these Plugins. This would allow projects to modify the plugin settings if needed.

Add:

config['bedrock-webpack'].pluginOptions = {
 cleanWebpackPlugin: {

 },
 htmlWebpackPlugin: {
   template: path.join(__dirname, '..', 'templates', 'index.html')
 },
 statsPlugin: {

 },
 terserPlugin: {

  },
  vueLoaderPlugin: {

  },
  progressPlugin: {

 },
 hotModuleReplacementPlugin: {

 },
 cleanWebpackPlugin: {

 }
}

Then inside of index.js simply reference this when creating a plugin.

new CleanWebpackPlugin(config.pluginOptions.cleanWebpackPlugin);

Why:

  1. As has recently been documented trying to merge the config of some plugins via WebpackConfigMerge causes issues
  2. Separates config options for plugins from index.js to config.js which increases code clarity and makes index.js cleaner
  3. Allows projects to more easily modify the WebPack Plugins this library uses by default
  4. Adheres closer to the config options seen in other bedrock libraries
  5. Reduces the need in config['bedrock-webpack'].configs for using non-json data structures such as classes