You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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')constbaseConfig={
...
plugins: [newBundleTracker({path: BUILD_DIR,filename: '../webpack-stats.json'}),newwebpack.ProgressPlugin(),newMiniCssExtractPlugin({...}),newwebpack.HotModuleReplacementPlugin(),newVueLoaderPlugin(),]
...
}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 pluginreturna.filter(p=>p.constructor.name!=='Plugin')}// fallback to default mergingreturnundefined}})(baseConfig,{...})
We're lucky that other plugins we enabled in base config all have reasonable names, for example:
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 😃 ).
The text was updated successfully, but these errors were encountered:
StephenPCG
changed the title
Can plugin constructor name be changed to 'BundleTrackerPlugin'
Can plugin's constructor name be changed to 'BundleTrackerPlugin'?
Mar 22, 2019
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:We're lucky that other plugins we enabled in base config all have reasonable names, for example:
ProgressPlugin
MiniCssExtractPlugin
HotModuleReplacementPlugin
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 😃 ).The text was updated successfully, but these errors were encountered: