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
This plugin has option to whitelist helpers, but what if it could detect which helpers are automatically injected and create whitelist from that?
I’ve made PoC based on Webpack 3 version of the plugin.
module.exports=function(compiler,pluginOptions){compiler.plugin('compilation',function(compilation,params){constinjectedBabelHelpers=[];params.normalModuleFactory.plugin('parser',(parser)=>{parser.plugin('call babelHelpers.*',(expr)=>{injectedBabelHelpers.push(expr.callee.property.name);});});inject(compilation,pluginOptions,injectedBabelHelpers);});};functioninject(compilation,pluginOptions,injectedBabelHelpers){compilation.dependencyFactories.set(SingleEntryDependencyWrapper,newNullFactory());compilation.plugin('seal',function(){// Babel helpers whitelist is available heregetChunks(this,pluginOptions.entries).forEach(chunk=>injectHelpers(this,chunk.module,pluginOptions.whitelist));});}// …
It uses Webpack parser to get all babelHelpers expressions from AST and stores methods used in array. That array is then passed down to inject method, at first it’s empty, but in seal phase it’s filled with all the helpers inside compiled module. It may seem like a hack, but as I said, this is PoC and it could possibliy be made better. Final array can then be filtered for duplicates and used instead of pluginOptions.whitelist.
This should of course be another plugin option and it should be opt-in.
What do you think? Am I missing something here?
The text was updated successfully, but these errors were encountered:
This plugin has option to whitelist helpers, but what if it could detect which helpers are automatically injected and create whitelist from that?
I’ve made PoC based on Webpack 3 version of the plugin.
It uses Webpack parser to get all
babelHelpers
expressions from AST and stores methods used in array. That array is then passed down toinject
method, at first it’s empty, but inseal
phase it’s filled with all the helpers inside compiled module. It may seem like a hack, but as I said, this is PoC and it could possibliy be made better. Final array can then be filtered for duplicates and used instead ofpluginOptions.whitelist
.This should of course be another plugin option and it should be opt-in.
What do you think? Am I missing something here?
The text was updated successfully, but these errors were encountered: