Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Can plugin's constructor name be changed to 'BundleTrackerPlugin'? #45

Closed
StephenPCG opened this issue Mar 22, 2019 · 2 comments
Closed
Milestone

Comments

@StephenPCG
Copy link

In the current code, the plugin constructor name is a generic name Plugin. The following case is why this is a concern.

We have a base webpack.config.js shared across all projects in our company. Each project will use webpack-merge to assign project specific customizations. A BundleTracker plugin is enabled in the base config file, however in one project we need to disable it. We use the webpack-merge's customizeArray feature to do this:

// const baseConfig = require('/path/to/base.config.js')
const baseConfig = {
  ...
  plugins: [
    new BundleTracker({ path: BUILD_DIR, filename: '../webpack-stats.json' }),
    new webpack.ProgressPlugin(),
    new MiniCssExtractPlugin({...}),
    new webpack.HotModuleReplacementPlugin(),
    new VueLoaderPlugin(),
  ]
  ...
}

module.exports = merge({
  customizeArray(a, b, key) {
    if (key === 'plugins') {
      // filter out bundle tracker plugin
      // XXX here we have no reliable way to identify the bundle tracker plugin
      return a.filter(p => p.constructor.name !== 'Plugin')
    }
    // fallback to default merging
    return undefined
  }
})(baseConfig, {...})

We're lucky that other plugins we enabled in base config all have reasonable names, for example:

  • webpack.ProgressPlugin: ProgressPlugin
  • MiniCssExtractPlugin: MiniCssExtractPlugin
  • webpack.HotModuleReplacementPlugin: HotModuleReplacementPlugin
  • VueLoaderPlugin: VueLoaderPlugin

so this approach works for us now. But I think it's not a good idea to write such code. On one hand, the reader won't understand why this code filters out the bundle tracker plugin, on the other hand, if any plugin we would use in the future also use Plugin as the name, it will be filtered out unexpectedly (in which case we will also report an issue to that project 😃 ).

@StephenPCG StephenPCG changed the title Can plugin constructor name be changed to 'BundleTrackerPlugin' Can plugin's constructor name be changed to 'BundleTrackerPlugin'? Mar 22, 2019
@owais
Copy link
Collaborator

owais commented Jan 8, 2020

I think we can do it as part of #52

@owais owais added this to the 1.0.0 milestone Jan 8, 2020
@andersk
Copy link
Contributor

andersk commented Oct 29, 2020

This was done in #53.

@andersk andersk closed this as completed Oct 29, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants