question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

custom webpack config with compression-webpack-plugin only compress es2015

See original GitHub issue

Describe the Bug

I believe there are so many people want to use compression-webpack-plugin to compress the generated js file and use it with static_gzip of nginx, and I’m one of these people.

I’ve used this great package for years, today I suddenly found that with angular 8.2, compression-webpack-plugin only compress the es2015 version of js files, the es-5 version is left uncompressed.

Minimal Reproduction

normal config like the readme, and here is my extra-webpack.config.js

const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');

module.exports = (config, options) => {

  // compress everything for nginx static_gzip
  config.plugins.push(
    new CompressionPlugin({
      test: /\.(js|css|svg|woff|woff2)$/,
      compressionOptions: { threshold: 8192, level: 9}
    })
  );

  return config;
};

with this simple config, the compress-plugin will only compress es2015 version.

Expected Behavior

should able to compress both es2015 and es-5 version of js.

Screenshots

截屏2019-11-2701 06 09

Environment


Libs
- @angular/core version: 8.2.14
- @angular-devkit/build-angular version: 0.803.19
- @angular-builders/custom-webpack version: 8.3.0

For Tooling issues:
- Node version: v10.17.0
- Platform:  only tested on Mac/Linux

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
arturovtcommented, Apr 11, 2020

Seems like it’s an Angular’s issue. Compression plugin “subscribes” on the emit hook and then runs compressions on files:

compiler.hooks.emit.tapAsync({
    name: 'CompressionPlugin'
}, (compilation, callback) => {
    console.log(Object.keys(compilation.assets));
})

All files are present except of main-es5 🤔

I guess it’s related to that differential loading process, emit hook is tapped right before assets are emitted to the dist folder, but the generation of ES5 bundles is started after that, you can open dist/project_name/static/assets and see that es-2015.js.gz files are emitted before es-5.js are generated.

I’m not a fan of that solution but you could try it as a temporary workaround. You could run gzip right after build command, like:

npm run build && gzip -rk9 dist

Same with brotli after installing brotli CLI.

1reaction
steve-todorovcommented, Mar 5, 2020

Sure, here’s the repo. This is just the hello world from the latest Angular 8 with some minor tweaks. When you run npm run build it should produce the mentioned issue. I’ve attached a screenshot and If you pay close attention to the *-es5-* assets you’ll see they have not been compressed. For example main-es5.e14fa0110cab463626ac.js. You can also check the assets-manifest.json which should have the es5 assets included, but does not. This is why I thought the es5 differential assets are actually generated after the entire build - maybe something like the index.html file.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

CompressionWebpackPlugin | webpack
Prepare compressed versions of assets to serve them with Content-Encoding. Getting Started. To begin, you'll need to install compression-webpack-plugin : npm ...
Read more >
Reduction of angular production build - Stack Overflow
I am using angular 9 and in order to reduce the bundle size I have used angular-builders/custom-webpack to compress the build files. Following ......
Read more >
How to write simple modern JavaScript apps with Webpack ...
We need a good custom build setup, so we will be using Webpack with the ... compression-webpack-plugin: For gzipping the dist folder file ......
Read more >
Webpack Configuration step by step - Development to ...
This guide, we not only cover configure webpack for development, ... server and then setup our project to use the latest JS features...
Read more >
Top 5 compression-webpack-plugin Code Examples - Snyk
css$/, threshold: 10240, minRatio: 0.8, }) ); } // Don't split bundles during testing, since we only want import one bundle if (!__TEST__)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found