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

feat(@angular/cli): add --compress option #4618

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
6 participants
@cherryland
Copy link

commented Feb 11, 2017

By default, gzip compression is enabled in production mode. There are several use cases, where gzip compression might not be supported and/or required

Usage

$ ng build --prod --compress=false

or

$ ng serve --prod --compress=false

Example Output

$ ng --help
ng build <options...>
  Builds your app and places it into the output path (dist/ by default).
  aliases: b
  --target (String) (Default: development)
    aliases: -t <value>, -dev (--target=development), -prod (--target=production)
  ...
  --compress (Boolean) (Default: true) use gzip compression in production mode
  ...

Basic Implementation

We simply wrap the plugin with a conditional operator and void the output, if the expression evaluates to false

  plugins: [
    ...
    buildOptions.compress ? new CompressionPlugin({...}) : (): void => null
  ]

This is perfectly fine, since Webpack installs a plugin by calling its apply method, passing a reference to the Webpack compiler object.

Related Issues

Related Pull Requests

feat(@angular/cli): add --compress option
Add compress option to toggle gzip compression in production mode
@googlebot

This comment has been minimized.

Copy link

commented Feb 11, 2017

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@googlebot googlebot added the cla: no label Feb 11, 2017

@cherryland

This comment has been minimized.

Copy link
Author

commented Feb 11, 2017

Awaiting #4596 to add e2e end-to-end tests

@googlebot

This comment has been minimized.

Copy link

commented Feb 11, 2017

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Feb 11, 2017

test: /\.js$|\.html$|\.css$/,
threshold: 10240
})
buildOptions.compress ?

This comment has been minimized.

Copy link
@clydin

clydin Feb 11, 2017

Member

It would be cleaner if a check was done above for buildOptions.compress and then the plugin was added onto extraPlugins. This should probably be moved into common instead if it's now configurable or a warning issued if it is only supported for production.

@filipesilva thoughts on this?

@@ -108,7 +108,7 @@ export default Task.extend({
stats: statsConfig,
inline: true,
proxy: proxyConfig,
compress: serveTaskOptions.target === 'production',
compress: serveTaskOptions.target === 'production' && serveTaskOptions.compress,

This comment has been minimized.

Copy link
@clydin

clydin Feb 11, 2017

Member

This should just be serveTaskOptions.compress once the option default is based on build target.

This comment has been minimized.

Copy link
@cherryland

cherryland Feb 11, 2017

Author

We need to make sure, that the compress option will only be available in combination with -t production, but this behavior can be changed in general

@filipesilva

@@ -25,6 +25,12 @@ export const baseBuildCommandOptions: any = [
{ name: 'locale', type: String },
{ name: 'extract-css', type: Boolean, aliases: ['ec'] },
{
name: 'compress',
type: Boolean,
default: true,

This comment has been minimized.

Copy link
@clydin

clydin Feb 11, 2017

Member

The default here can be removed as it can be set based on build target. This can be done by adding the option values here: https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/models/webpack-config.ts#L79

This comment has been minimized.

Copy link
@cherryland

cherryland Feb 11, 2017

Author

This can be done by adding the option values here: https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/models/webpack-config.ts#L79

It already is

The default here can be removed

I disagree, the default value may be redundant here, but is also included in the CLI help output

This comment has been minimized.

Copy link
@clydin

clydin Feb 11, 2017

Member

Except the default is false for the development target which makes it misleading in its current form. I know it says production in the description but even a small amount of ambiguity can lead to confusion.

Either way, help should eventually support displaying target specific defaults.

This comment has been minimized.

@hansl

This comment has been minimized.

Copy link
Contributor

commented Feb 11, 2017

Hi @0xCHERRY,

After an offline discussion here with the team we decided to remove the compression plugin entirely. The reasoning is that there is an easy workaround, it's noise and the service worker is buggy with it.

Could you transform this PR with:

  1. remove compression plugin on production builds all the time,
  2. add a documentation to /doc/documentation explaining how to compress the files, in case users miss the functionality, and
  3. add a BREAKING CHANGE section to your commit message explaining that those files are not outputted anymore.

If you need any help with the above steps let me know.

Cheers!

@hansl
Copy link
Contributor

left a comment

See above.

filipesilva added a commit to filipesilva/angular-cli that referenced this pull request Feb 14, 2017

@filipesilva

This comment has been minimized.

Copy link
Member

commented Feb 14, 2017

Superseded by #4702

filipesilva added a commit to filipesilva/angular-cli that referenced this pull request Feb 14, 2017

filipesilva added a commit that referenced this pull request Feb 14, 2017

asnowwolf added a commit to asnowwolf/angular-cli that referenced this pull request Apr 12, 2017

@iamdenny

This comment has been minimized.

Copy link

commented Oct 20, 2018

I can't find compress doc in https://github.com/angular/angular-cli/tree/master/docs/documentation
please let me where it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.