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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ or `ng serve --prod` will also make use of uglifying and tree-shaking functional

`--extract-css` (`-ec`) extract css from global styles onto css files instead of js ones

`--compress` use gzip compression in production mode

`--output-hashing` define the output filename cache-busting hashing mode
2 changes: 2 additions & 0 deletions docs/documentation/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@

`--extract-css` (`-ec`) extract css from global styles onto css files instead of js ones

`--compress` use gzip compression in production mode

`--output-hashing` define the output filename cache-busting hashing mode
6 changes: 6 additions & 0 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const baseBuildCommandOptions: any = [
{ name: 'i18n-format', type: String },
{ name: 'locale', type: String },
{ name: 'extract-css', type: Boolean, aliases: ['ec'] },
{
name: 'compress',
type: Boolean,
default: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@clydin clydin Feb 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description: 'use gzip compression in production mode'
},
{
name: 'output-hashing',
type: String,
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/models/build-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export interface BuildOptions {
i18nFormat?: string;
locale?: string;
extractCss?: boolean;
compress?: boolean;
outputHashing?: string;
}
1 change: 1 addition & 0 deletions packages/@angular/cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class NgCliWebpackConfig {
outputHashing: 'all',
sourcemap: false,
extractCss: true,
compress: true,
aot: true
}
};
Expand Down
13 changes: 7 additions & 6 deletions packages/@angular/cli/models/webpack-configs/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
compress: { screw_ie8: true, warnings: buildOptions.verbose },
sourceMap: buildOptions.sourcemap
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.html$|\.css$/,
threshold: 10240
})
buildOptions.compress ?
Copy link
Member

@clydin clydin Feb 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.html$|\.css$/,
threshold: 10240
}) : (): void => null
].concat(extraPlugins)
};
};
2 changes: 1 addition & 1 deletion packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default Task.extend({
stats: statsConfig,
inline: true,
proxy: proxyConfig,
compress: serveTaskOptions.target === 'production',
compress: serveTaskOptions.target === 'production' && serveTaskOptions.compress,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

watchOptions: {
poll: projectConfig.defaults && projectConfig.defaults.poll
},
Expand Down