Open mman opened 6 months ago
The original commit here https://github.com/victronenergy/venus-html5-app/commit/793fc13294fac534fbaf755f4a815bf7e4f43305 was supposed to enable WebpackCompressionPlugin
. However WebpackCompressionPlugin
seems to be broken and does not play well with HtmlWebpackPlugin
when deleteOriginalAssets: true
.
I have filed two related bugs here:
https://github.com/webpack-contrib/compression-webpack-plugin/issues/390
https://github.com/webpack-contrib/compression-webpack-plugin/issues/389
I have temporarily fixed this by reverting the original commit, here: https://github.com/victronenergy/venus-html5-app/commit/bea62d00544e92af1b56017bf666228046868d7a, leaving open for investigation how to properly implement gzip + delete
One of the recent commits https://github.com/victronenergy/venus-html5-app/commit/9bb36644b1cc08c280104f1b8cad9b90907afd50 that I assume was supposed to reduce disk space and network traffic went wrong and broke the build.
Building the HTML5 app uses https://github.com/webpack-contrib/compression-webpack-plugin as a last step to compress files exceeding certain size.
The plugin works in a way where during the
npm run build
it leaves original files produced bywebpack
in place, and produces a.gz
versions of all files that exceed the threshold specified in webpack config:https://github.com/victronenergy/venus-html5-app/blob/9bb36644b1cc08c280104f1b8cad9b90907afd50/config/webpack.config.js#L687-L690
When using
deleteOriginalAssets: true
the plugin actually removes the uncompressed original files as they are not actually needed on the serverSo a directory produced with
deleteOriginalAssets: false
:Will look like this when
deleteOriginalAssets: true
is used:This all looks nice and shiny, until we realise there is
Problem 1: LICENSE.txt file gets deleted as well
We can see that it not only deleted the original
.js
file, but it also accidentally got rid of the.js.LICENSE.txt
file that gets shipped along... This is probably a bug in theCompressionPlugin
.Problem 2: Deleted original
.js
file does not get injected intoindex.html
There seems to be a race condition between the
CompressionPlugin
and theHtmlWebpackPlugin
whereHTMLWebpackPlugin
does not properly inject required.js
files into theindex.html
when they are removed by theCompressionPlugin
. This should not happen asCompressionPlugin
is mentioned last in ourwebpack.config
but it does happen.The result is that running either the
npm run build
ornpm run start
both result in an empty HTML5 app...Simple fix is to revert the commit https://github.com/victronenergy/venus-html5-app/commit/9bb36644b1cc08c280104f1b8cad9b90907afd50.
More complex fix is to figure out how to make
CompressionPlugin
play well withHtmlWebpackPlugin
.