sagold / handlebars-webpack-plugin

Renders your html-template at build time
161 stars 45 forks source link

Webpack 4 updates #28

Closed vitapluvia closed 6 years ago

vitapluvia commented 6 years ago

Hi!

This has been a very useful plugin! While attempting to upgrade to Webpack 4 I noticed it started to break, and it was fairly simple to fix locally. This is a sample of the type of error one would run into:

compilation.fileDependencies.concat is not a function

The new Webpack 4 changes include differences in core data-structures, as mentioned in this article - https://medium.com/webpack/webpack-4-changes-part-1-week-24-25-fd4d77674e55 Also looks like there was an article posted yesterday about Webpack 4 migration for plugins & loaders - https://medium.com/webpack/webpack-4-migration-guide-for-plugins-loaders-20a79b927202

This line seems to be breaking, but could be fixed easily: https://github.com/sagold/handlebars-webpack-plugin/blob/master/index.js#L88

For Webpack 4 support, it looks like this should be changed to:

compilation.fileDependencies = compilation.fileDependencies.add(...this.fileDependencies);

To support earlier versions, you could use both and check for existence of the .concat method, or check the data type of compilation.fileDependencies.

mkungla commented 6 years ago

until merged or fixed one can use

yarn add -D github:mkungla/handlebars-webpack-plugin#911b9d1
## OR ##
npm i -D github:mkungla/handlebars-webpack-plugin#911b9d1
sagold commented 6 years ago

Hi vitapluvia.

Thanks for that detailed explanation. The fix has been released with v1.3.3 2b6abadce1e82ac252852a8e76d6783fb8696956.

Just a side note: Set.add does not support multiple arguments. I did go with this.fileDependencies.forEach(compilation.fileDependencies.add, compilation.fileDependencies);

Regards. sagold