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

2.0.1 TypeError: Cannot read property 'tap' of undefined #46

Closed cyqresig closed 6 years ago

cyqresig commented 6 years ago

TypeError: Cannot read property 'tap' of undefined at ScriptExtHtmlWebpackPlugin.compilationCallback (/Users/user/temp/peon-react-redux-test/node_modules/script-ext-html-webpack-plugin/lib/plugin.js:50:56)

while executing the code next line compilation.hooks.htmlWebpackPluginAlterAssetTags.tap(PLUGIN, alterAssetTags); 'compilation.hooks.htmlWebpackPluginAlterAssetTags' is undefined. but html-webpack-plugin works well. I'm so confused about it.

script-ext-html-webpack-plugin 2.0.1 html-webpack-plugin 3.2.0 webpack 4.7.0

MQuy commented 6 years ago

I solved the issue by moving script-ext-html-webpack-plugin under html-webpack-plugin in plugins

cyqresig commented 6 years ago

@MQuy Thank u for the answer. Now it works.

grzegorzjudas commented 6 years ago

I get exactly the same error when used along with speed-measure-webpack-plugin, even if the order of plugins is the one mentioned above...

Works just fine if I disable the speed-measure-webpack-plugin. Should I raise a separate issue?

abcdGJJ commented 6 years ago

@grzegorzjudas I have the same question, have you solve it?

grzegorzjudas commented 6 years ago

Not really, I've used --env.perfcheck flag in order to conditionally enable speed-measure-webpack-plugin and disable script-ext-html-webpack-plugin.

The resulting build of course doesn't work because the script tag doesn't have "defer" in it, but I can still reliably check the build time.

ghost commented 6 years ago

@MQuy Thank u for the answer. Now it works.

new HtmlWebpackPlugin({
     template: path.resolve(__dirname, './public/index.html')
}),
new ScriptExtHtmlWebpackPlugin({
      inline: /runtime\..*\.js$/
})

问题依然存在