Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: npm run build produces non functioning app... #370

Open
mman opened this issue May 21, 2024 · 2 comments
Open

bug: npm run build produces non functioning app... #370

mman opened this issue May 21, 2024 · 2 comments
Labels
bug Something isn't working pending-external-change Requires work in Venus, Mqtt or other external systems

Comments

@mman
Copy link
Collaborator

mman commented May 21, 2024

One of the recent commits 9bb3664 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 by webpack in place, and produces a .gz versions of all files that exceed the threshold specified in webpack config:

new CompressionPlugin({
threshold: 500000,
deleteOriginalAssets: true,
})

When using deleteOriginalAssets: true the plugin actually removes the uncompressed original files as they are not actually needed on the server

So a directory produced with deleteOriginalAssets: false:

-rw-r--r--  1 mman  staff  1423307 May 21 11:42 60.96569f9e.js
-rw-r--r--  1 mman  staff     2881 May 21 11:42 60.96569f9e.js.LICENSE.txt
-rw-r--r--  1 mman  staff   421274 May 21 11:42 60.96569f9e.js.gz
-rw-r--r--  1 mman  staff   160371 May 21 11:42 main.c742e74d.js
-rw-r--r--  1 mman  staff     1818 May 21 11:42 runtime-main.17566f78.js

Will look like this when deleteOriginalAssets: true is used:

-rw-r--r--  1 mman  staff   421274 May 21 11:42 60.96569f9e.js.gz
-rw-r--r--  1 mman  staff   160371 May 21 11:42 main.c742e74d.js
-rw-r--r--  1 mman  staff     1818 May 21 11:42 runtime-main.17566f78.js

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 the CompressionPlugin.

Problem 2: Deleted original .js file does not get injected into index.html

There seems to be a race condition between the CompressionPlugin and the HtmlWebpackPlugin where HTMLWebpackPlugin does not properly inject required .js files into the index.html when they are removed by the CompressionPlugin. This should not happen as CompressionPlugin is mentioned last in our webpack.config but it does happen.

The result is that running either the npm run build or npm run start both result in an empty HTML5 app...

Screenshot 2024-05-21 at 11 25 04

Simple fix is to revert the commit 9bb3664.

More complex fix is to figure out how to make CompressionPlugin play well with HtmlWebpackPlugin.

@mman
Copy link
Collaborator Author

mman commented May 22, 2024

The original commit here 793fc13 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:

webpack-contrib/compression-webpack-plugin#390

webpack-contrib/compression-webpack-plugin#389

@mman
Copy link
Collaborator Author

mman commented May 22, 2024

I have temporarily fixed this by reverting the original commit, here: bea62d0, leaving open for investigation how to properly implement gzip + delete

@mman mman added the bug Something isn't working label May 22, 2024
@mman mman added the pending-external-change Requires work in Venus, Mqtt or other external systems label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending-external-change Requires work in Venus, Mqtt or other external systems
Projects
None yet
Development

No branches or pull requests

1 participant