Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): use copy-on-write asset processin…
Browse files Browse the repository at this point in the history
…g for non-watch builds

Optimized asset processing was only being performed when differential loading was enabled.  This change ensures that the optimized approach is used for non-watch builds.  This does not affect `ng serve` usage since it currently requires all application files to be in memory.

(cherry picked from commit 3c734a8)
  • Loading branch information
clydin authored and filipesilva committed Jul 1, 2020
1 parent 766cb06 commit f22efa1
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,31 @@ async function initialize(
i18n: I18nOptions;
}> {
const originalOutputPath = options.outputPath;

// Assets are processed directly by the builder except when watching
const adjustedOptions = options.watch ? options : { ...options, assets: [] };

const {
config,
projectRoot,
projectSourceRoot,
i18n,
} = await buildBrowserWebpackConfigFromContext(options, context, host, true);
} = await buildBrowserWebpackConfigFromContext(adjustedOptions, context, host, true);

// Validate asset option values if processed directly
if (options.assets?.length && !adjustedOptions.assets?.length) {
normalizeAssetPatterns(
options.assets,
new virtualFs.SyncDelegateHost(host),
normalize(context.workspaceRoot),
normalize(projectRoot),
projectSourceRoot === undefined ? undefined : normalize(projectSourceRoot),
).forEach(({ output }) => {
if (output.startsWith('..')) {
throw new Error('An asset cannot be written to a location outside of the output path.');
}
});
}

let transformedConfig;
if (webpackConfigurationTransform) {
Expand Down Expand Up @@ -573,27 +592,6 @@ export function buildWebpackBrowser(
executor.stop();
}

// Copy assets
if (options.assets) {
try {
await copyAssets(
normalizeAssetPatterns(
options.assets,
new virtualFs.SyncDelegateHost(host),
root,
normalize(projectRoot),
projectSourceRoot === undefined ? undefined : normalize(projectSourceRoot),
),
Array.from(outputPaths.values()),
context.workspaceRoot,
);
} catch (err) {
context.logger.error('Unable to copy assets: ' + err.message);

return { success: false };
}
}

type ArrayElement<A> = A extends ReadonlyArray<infer T> ? T : never;
function generateBundleInfoStats(
id: string | number,
Expand Down Expand Up @@ -698,6 +696,27 @@ export function buildWebpackBrowser(
}
}

// Copy assets
if (!options.watch && options.assets) {
try {
await copyAssets(
normalizeAssetPatterns(
options.assets,
new virtualFs.SyncDelegateHost(host),
root,
normalize(projectRoot),
projectSourceRoot === undefined ? undefined : normalize(projectSourceRoot),
),
Array.from(outputPaths.values()),
context.workspaceRoot,
);
} catch (err) {
context.logger.error('Unable to copy assets: ' + err.message);

return { success: false };
}
}

if (options.index) {
for (const [locale, outputPath] of outputPaths.entries()) {
let localeBaseHref;
Expand Down

0 comments on commit f22efa1

Please sign in to comment.