Skip to content

Commit 520459e

Browse files
alan-agius4clydin
authored andcommitted
refactor: minor cleanup to common webpack configuration
1 parent 30e8f33 commit 520459e

File tree

2 files changed

+22
-26
lines changed
  • packages/angular_devkit/build_angular/src/angular-cli-files

2 files changed

+22
-26
lines changed

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

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -235,23 +235,19 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
235235
return prev;
236236
}, []);
237237

238-
if (globalScriptsByBundleName.length > 0) {
239238
// Add a new asset for each entry.
240-
globalScriptsByBundleName.forEach(script => {
241-
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
242-
const hash = script.inject ? hashFormat.script : '';
243-
const bundleName = script.bundleName;
244-
245-
extraPlugins.push(
246-
new ScriptsWebpackPlugin({
247-
name: bundleName,
248-
sourceMap: scriptsSourceMap,
249-
filename: `${path.basename(bundleName)}${hash}.js`,
250-
scripts: script.paths,
251-
basePath: projectRoot,
252-
}),
253-
);
254-
});
239+
for (const script of globalScriptsByBundleName) {
240+
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
241+
const hash = script.inject ? hashFormat.script : '';
242+
const bundleName = script.bundleName;
243+
244+
extraPlugins.push(new ScriptsWebpackPlugin({
245+
name: bundleName,
246+
sourceMap: scriptsSourceMap,
247+
filename: `${path.basename(bundleName)}${hash}.js`,
248+
scripts: script.paths,
249+
basePath: projectRoot,
250+
}));
255251
}
256252

257253
// process asset entries
@@ -353,12 +349,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
353349
];
354350
}
355351

356-
// Allow loaders to be in a node_modules nested inside the devkit/build-angular package.
357-
// This is important in case loaders do not get hoisted.
358-
// If this file moves to another location, alter potentialNodeModules as well.
359-
const loaderNodeModules = findAllNodeModules(__dirname, projectRoot);
360-
loaderNodeModules.unshift('node_modules');
361-
362352
const extraMinimizers = [];
363353
if (stylesOptimization) {
364354
extraMinimizers.push(
@@ -493,14 +483,20 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
493483
},
494484
resolveLoader: {
495485
symlinks: !buildOptions.preserveSymlinks,
496-
modules: loaderNodeModules,
486+
modules: [
487+
// Allow loaders to be in a node_modules nested inside the devkit/build-angular package.
488+
// This is important in case loaders do not get hoisted.
489+
// If this file moves to another location, alter potentialNodeModules as well.
490+
'node_modules',
491+
...findAllNodeModules(__dirname, projectRoot),
492+
],
497493
plugins: [PnpWebpackPlugin.moduleLoader(module)],
498494
},
499495
context: projectRoot,
500496
entry: entryPoints,
501497
output: {
502498
futureEmitAssets: true,
503-
path: path.resolve(root, buildOptions.outputPath as string),
499+
path: path.resolve(root, buildOptions.outputPath),
504500
publicPath: buildOptions.deployUrl,
505501
filename: `[name]${targetInFileName}${hashFormat.chunk}.js`,
506502
},

packages/angular_devkit/build_angular/src/angular-cli-files/utilities/find-up.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { existsSync } from 'fs';
99
import * as path from 'path';
1010
import { isDirectory } from './is-directory';
1111

12-
export function findUp(names: string | string[], from: string, stopOnNodeModules = false) {
12+
export function findUp(names: string | string[], from: string, stopOnNodeModules = false): string | null {
1313
if (!Array.isArray(names)) {
1414
names = [names];
1515
}
@@ -37,7 +37,7 @@ export function findUp(names: string | string[], from: string, stopOnNodeModules
3737
return null;
3838
}
3939

40-
export function findAllNodeModules(from: string, root?: string) {
40+
export function findAllNodeModules(from: string, root?: string): string[] {
4141
const nodeModules: string[] = [];
4242

4343
let current = from;

0 commit comments

Comments
 (0)