Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
fix(@angular-devkit/build-angular): remove mangle and compress from s…
Browse files Browse the repository at this point in the history
…erver build

Using those for server might break the runtime, and since it all runs on the server
we dont need to compress, local name mangling works fine. Also remove the build
optimizer pass on server optimized builds.

Partial fix for angular/angular-cli#8616 (need to have a fix for 1.7.x)
  • Loading branch information
hansl committed May 9, 2018
1 parent a71f489 commit fbfd323
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
alias = rxPaths(nodeModules);
} catch (e) { }

const uglifyOptions = {
ecma: wco.supportES2015 ? 6 : 5,
warnings: !!buildOptions.verbose,
safari10: true,
output: {
ascii_only: true,
comments: false,
webkit: true,
},

// On server, we don't want to compress anything.
...(buildOptions.platform == 'server' ? {} : {
compress: {
pure_getters: buildOptions.buildOptimizer,
// PURE comments work best with 3 passes.
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
passes: buildOptions.buildOptimizer ? 3 : 1,
// Workaround known uglify-es issue
// See https://github.com/mishoo/UglifyJS2/issues/2949#issuecomment-368070307
inline: wco.supportES2015 ? 1 : 3,
}
}),
// We also want to avoid mangling on server.
...(buildOptions.platform == 'server' ? { mangle: false } : {})
};

return {
mode: buildOptions.optimization ? 'production' : 'development',
devtool: false,
Expand Down Expand Up @@ -278,25 +304,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
sourceMap: buildOptions.sourceMap,
parallel: true,
cache: true,
uglifyOptions: {
ecma: wco.supportES2015 ? 6 : 5,
warnings: buildOptions.verbose,
safari10: true,
compress: {
pure_getters: buildOptions.buildOptimizer,
// PURE comments work best with 3 passes.
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
passes: buildOptions.buildOptimizer ? 3 : 1,
// Workaround known uglify-es issue
// See https://github.com/mishoo/UglifyJS2/issues/2949#issuecomment-368070307
inline: wco.supportES2015 ? 1 : 3,
},
output: {
ascii_only: true,
comments: false,
webkit: true,
},
}
uglifyOptions,
}),
],
},
Expand Down
16 changes: 4 additions & 12 deletions packages/angular_devkit/build_angular/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,10 @@ export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
: of(null)),
concatMap(() => addFileReplacements(root, host, options.fileReplacements)),
concatMap(() => new Observable(obs => {
concatMap(() => addFileReplacements(root, host, options.fileReplacements)),
concatMap(() => new Observable(obs => {
// Ensure Build Optimizer is only used with AOT.
let webpackConfig;
try {
webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
} catch (e) {
// TODO: why do I have to catch this error? I thought throwing inside an observable
// always got converted into an error.
obs.error(e);

return;
}
const webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
const webpackCompiler = webpack(webpackConfig);
const statsConfig = getWebpackStatsConfig(options.verbose);

Expand Down Expand Up @@ -132,6 +123,7 @@ export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
// TODO: use only this.options, it contains all flags and configs items already.
buildOptions: {
...buildOptions,
buildOptimizer: false,
aot: true,
platform: 'server',
scripts: [],
Expand Down

0 comments on commit fbfd323

Please sign in to comment.