numical / script-ext-html-webpack-plugin

Enhances html-webpack-plugin functionality with different deployment options for your scripts including 'async', 'preload', 'prefetch', 'defer', 'module', custom attributes, and inlining.
MIT License
588 stars 105 forks source link

Support custom value callback #44

Closed devpreview closed 6 years ago

devpreview commented 6 years ago

For example:

new ScriptExtHtmlWebpackPlugin({
  custom: [
    {
      test: /\.js$/,
      attribute: 'onload',
      value: (entry) => {return 'alert("loaded ' + entry + '");'}
     }
   ]
}),
numical commented 6 years ago

Can you explain the use case? When is the function called and what is passed to it?

lili21 commented 6 years ago

I think it would be useful for things like tracking the resources which load failed.

new ScriptExtHtmlWebpackPlugin({
  custom: [
    {
      test: /\.js$/,
      attribute: 'onerror',
      value: e => { // track the resource }
     }
   ]
}),
numical commented 6 years ago

Sorry - still not clear on when the function wuld be called and hat data would be passed. Happy to re-open if more clarity available - or better a spike-PR! :-)

ykxkknd2 commented 5 years ago

@numical I need this too. For example, When the resource requested fails, and the error event is reported to the log.The callback parameter is the filename. Like this

new ScriptExtHtmlWebpackPlugin({
  custom: [
    {
      test: /\.js$/,
      attribute: 'onerror',
      value: filename => report(filename)
     }
   ]
}),