Skip to content

Commit

Permalink
refactor: minor cleanup to common webpack configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 authored and clydin committed Aug 4, 2020
1 parent 30e8f33 commit 520459e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,19 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
return prev;
}, []);

if (globalScriptsByBundleName.length > 0) {
// Add a new asset for each entry.
globalScriptsByBundleName.forEach(script => {
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
const hash = script.inject ? hashFormat.script : '';
const bundleName = script.bundleName;

extraPlugins.push(
new ScriptsWebpackPlugin({
name: bundleName,
sourceMap: scriptsSourceMap,
filename: `${path.basename(bundleName)}${hash}.js`,
scripts: script.paths,
basePath: projectRoot,
}),
);
});
for (const script of globalScriptsByBundleName) {
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
const hash = script.inject ? hashFormat.script : '';
const bundleName = script.bundleName;

extraPlugins.push(new ScriptsWebpackPlugin({
name: bundleName,
sourceMap: scriptsSourceMap,
filename: `${path.basename(bundleName)}${hash}.js`,
scripts: script.paths,
basePath: projectRoot,
}));
}

// process asset entries
Expand Down Expand Up @@ -353,12 +349,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
];
}

// Allow loaders to be in a node_modules nested inside the devkit/build-angular package.
// This is important in case loaders do not get hoisted.
// If this file moves to another location, alter potentialNodeModules as well.
const loaderNodeModules = findAllNodeModules(__dirname, projectRoot);
loaderNodeModules.unshift('node_modules');

const extraMinimizers = [];
if (stylesOptimization) {
extraMinimizers.push(
Expand Down Expand Up @@ -493,14 +483,20 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
},
resolveLoader: {
symlinks: !buildOptions.preserveSymlinks,
modules: loaderNodeModules,
modules: [
// Allow loaders to be in a node_modules nested inside the devkit/build-angular package.
// This is important in case loaders do not get hoisted.
// If this file moves to another location, alter potentialNodeModules as well.
'node_modules',
...findAllNodeModules(__dirname, projectRoot),
],
plugins: [PnpWebpackPlugin.moduleLoader(module)],
},
context: projectRoot,
entry: entryPoints,
output: {
futureEmitAssets: true,
path: path.resolve(root, buildOptions.outputPath as string),
path: path.resolve(root, buildOptions.outputPath),
publicPath: buildOptions.deployUrl,
filename: `[name]${targetInFileName}${hashFormat.chunk}.js`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { existsSync } from 'fs';
import * as path from 'path';
import { isDirectory } from './is-directory';

export function findUp(names: string | string[], from: string, stopOnNodeModules = false) {
export function findUp(names: string | string[], from: string, stopOnNodeModules = false): string | null {
if (!Array.isArray(names)) {
names = [names];
}
Expand Down Expand Up @@ -37,7 +37,7 @@ export function findUp(names: string | string[], from: string, stopOnNodeModules
return null;
}

export function findAllNodeModules(from: string, root?: string) {
export function findAllNodeModules(from: string, root?: string): string[] {
const nodeModules: string[] = [];

let current = from;
Expand Down

0 comments on commit 520459e

Please sign in to comment.