preload-webpack-plugin icon indicating copy to clipboard operation
preload-webpack-plugin copied to clipboard

Support html-webpack-plugin v4

Open edmorley opened this issue 5 years ago • 13 comments

Hi

The upcoming html-webpack-plugin v4 (currently at 4.0.0-beta.1) has changed the name of several of its hooks, which causes:

Syntax error: Unable to tap into the HtmlWebpackPlugin's callbacks. Make sure to list
PreloadPlugin at some point after HtmlWebpackPlugin in webpack's plugins array.

(See: https://github.com/facebook/create-react-app/issues/5103#issuecomment-425461268)

The new hook names are described here: https://github.com/jantimon/html-webpack-plugin/pull/953#issue-189369685

Many thanks :-)

edmorley avatar Sep 28 '18 15:09 edmorley

That's fun 😄

We can add in html-webpack-plugin v4 compatibility as part of the v3.0.0-beta releases, and then hopefully move that to be a final v3.0.0 release in the near future.

jeffposnick avatar Sep 28 '18 15:09 jeffposnick

Sorry for the lack of updates—I've been trying to get things upgraded for html-webpack-plugin v4 (in the same branch that added support for webpack v4), and run into a couple of issues:

  • https://github.com/jantimon/html-webpack-plugin/issues/1091
  • https://github.com/jantimon/html-webpack-plugin/issues/1092

jeffposnick avatar Oct 25 '18 21:10 jeffposnick

Hey all—could folks give npm install [email protected] a try?

That is meant to add support for html-webpack-plugin v4, but I did have to remove a some features in the process (like support for include: allChunks, due to https://github.com/jantimon/html-webpack-plugin/issues/1092).

jeffposnick avatar Oct 31 '18 14:10 jeffposnick

@jeffposnick works great! thanks! I'm using: {rel: "prefetch", include: "allAssets"}

ghost avatar Oct 31 '18 14:10 ghost

Thanks—I'm still working out some of the ergonomics with html-webpack-plugin v4 (see https://github.com/jantimon/html-webpack-plugin/issues/1091#issuecomment-434708455), but that at least gives folks who are on the bleeding edge something to work with 😄

jeffposnick avatar Oct 31 '18 15:10 jeffposnick

howdy, worked first time with

module.exports = new PreloadWebpackPlugin({
    rel: 'preload',
    include: 'initial', // 'initial' or 'allChunks'
});
 "preload-webpack-plugin": "^3.0.0-beta.3",
 "html-webpack-plugin": "^4.0.0-beta.2",

👏 👏 👍

phil-lgr avatar Nov 08 '18 20:11 phil-lgr

Just wondering if there are any updates on supporting Webpack 4+ in upcoming release and when it may be? Thank you.

pgregorova avatar Jan 15 '19 15:01 pgregorova

@phil-lgr good job! I had resolved.

Tim-ls avatar Jan 18 '19 02:01 Tim-ls

So both https://github.com/jantimon/html-webpack-plugin/issues/1091 and https://github.com/jantimon/html-webpack-plugin/issues/1092 remain open, with the first issue being more serious with regards to how this plugin integrates with html-webpack-plugin v4.

npm install [email protected] should give folks something that works with the latest html-webpack-plugin v4 beta, but I'm a little hesitant to make that a final release while the underlying html-webpack-plugin interface is still up in the air.

jeffposnick avatar Jan 18 '19 16:01 jeffposnick

Adding my name to this in the hope that we can get v4 support.

Would the Vue version of this package provide a way through the impasse? I notice they state the following:

Uses a combination of htmlWebpackPluginBeforeHtmlProcessing and htmlWebpackPluginAlterAssetTags hooks to inject links as objects rather than strings. This allows for more flexibility when the tags need to be altered by other plugins.

I'm not very experienced with the details but it sounds like they may have experienced similar issues? For reference, I tried using the Vue version but I just get Cannot read property 'tap' of undefined when trying to build.

andyfurniss4 avatar Mar 28 '19 10:03 andyfurniss4

This issue has been open for over a year and is still not closed.

Since even create-react-app uses html-webpack-plugin 4.0.0-beta.5, I would assume it's stable enough to base an update off of the most recent interface.

For those looking to resolve this issue without this plugin, look into magic comments.

EliteMasterEric avatar Nov 08 '19 21:11 EliteMasterEric

No need for magic comments. You can use the preload-webpack-plugin@next, which installs the latest, in which Webpack 4 support has been added. I tested with 3.0.0-beta.4 See the release page.

glassdimlygr avatar Apr 29 '20 17:04 glassdimlygr

not working with html-webpack-plugin version > 4.0.0

alireza-mh avatar Oct 14 '20 13:10 alireza-mh