Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 577fa91

Browse files
hanslfilipesilva
authored andcommitted
fix(@angular-devkit/build-angular): remove mangle and compress from server 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)
1 parent c535c8e commit 577fa91

File tree

2 files changed

+31
-31
lines changed
  • packages/angular_devkit/build_angular/src

2 files changed

+31
-31
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

+27-19
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,32 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
207207
alias = rxPaths(nodeModules);
208208
} catch (e) { }
209209

210+
const uglifyOptions = {
211+
ecma: wco.supportES2015 ? 6 : 5,
212+
warnings: !!buildOptions.verbose,
213+
safari10: true,
214+
output: {
215+
ascii_only: true,
216+
comments: false,
217+
webkit: true,
218+
},
219+
220+
// On server, we don't want to compress anything.
221+
...(buildOptions.platform == 'server' ? {} : {
222+
compress: {
223+
pure_getters: buildOptions.buildOptimizer,
224+
// PURE comments work best with 3 passes.
225+
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
226+
passes: buildOptions.buildOptimizer ? 3 : 1,
227+
// Workaround known uglify-es issue
228+
// See https://github.com/mishoo/UglifyJS2/issues/2949#issuecomment-368070307
229+
inline: wco.supportES2015 ? 1 : 3,
230+
}
231+
}),
232+
// We also want to avoid mangling on server.
233+
...(buildOptions.platform == 'server' ? { mangle: false } : {})
234+
};
235+
210236
return {
211237
mode: buildOptions.optimization ? 'production' : 'development',
212238
devtool: false,
@@ -278,25 +304,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
278304
sourceMap: buildOptions.sourceMap,
279305
parallel: true,
280306
cache: true,
281-
uglifyOptions: {
282-
ecma: wco.supportES2015 ? 6 : 5,
283-
warnings: buildOptions.verbose,
284-
safari10: true,
285-
compress: {
286-
pure_getters: buildOptions.buildOptimizer,
287-
// PURE comments work best with 3 passes.
288-
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
289-
passes: buildOptions.buildOptimizer ? 3 : 1,
290-
// Workaround known uglify-es issue
291-
// See https://github.com/mishoo/UglifyJS2/issues/2949#issuecomment-368070307
292-
inline: wco.supportES2015 ? 1 : 3,
293-
},
294-
output: {
295-
ascii_only: true,
296-
comments: false,
297-
webkit: true,
298-
},
299-
}
307+
uglifyOptions,
300308
}),
301309
],
302310
},

packages/angular_devkit/build_angular/src/server/index.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,10 @@ export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
5454
concatMap(() => options.deleteOutputPath
5555
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
5656
: of(null)),
57-
concatMap(() => addFileReplacements(root, host, options.fileReplacements)),
58-
concatMap(() => new Observable(obs => {
57+
concatMap(() => addFileReplacements(root, host, options.fileReplacements)),
58+
concatMap(() => new Observable(obs => {
5959
// Ensure Build Optimizer is only used with AOT.
60-
let webpackConfig;
61-
try {
62-
webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
63-
} catch (e) {
64-
// TODO: why do I have to catch this error? I thought throwing inside an observable
65-
// always got converted into an error.
66-
obs.error(e);
67-
68-
return;
69-
}
60+
const webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
7061
const webpackCompiler = webpack(webpackConfig);
7162
const statsConfig = getWebpackStatsConfig(options.verbose);
7263

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

0 commit comments

Comments
 (0)