fix(webpack): restore supporting a configuration array (#14977)
This commit is contained in:
parent
347d6dd920
commit
2a77436118
@ -1,9 +1,15 @@
|
|||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { ExecutorContext, logger } from '@nrwl/devkit';
|
import { ExecutorContext, logger } from '@nrwl/devkit';
|
||||||
import { eachValueFrom } from '@nrwl/devkit/src/utils/rxjs-for-await';
|
import { eachValueFrom } from '@nrwl/devkit/src/utils/rxjs-for-await';
|
||||||
import type { Configuration } from 'webpack';
|
import type { Configuration, Stats } from 'webpack';
|
||||||
import { of } from 'rxjs';
|
import { from, of } from 'rxjs';
|
||||||
import { switchMap, tap } from 'rxjs/operators';
|
import {
|
||||||
|
bufferCount,
|
||||||
|
mergeMap,
|
||||||
|
mergeScan,
|
||||||
|
switchMap,
|
||||||
|
tap,
|
||||||
|
} from 'rxjs/operators';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import {
|
import {
|
||||||
calculateProjectDependencies,
|
calculateProjectDependencies,
|
||||||
@ -23,7 +29,7 @@ import { normalizeOptions } from './lib/normalize-options';
|
|||||||
async function getWebpackConfigs(
|
async function getWebpackConfigs(
|
||||||
options: NormalizedWebpackExecutorOptions,
|
options: NormalizedWebpackExecutorOptions,
|
||||||
context: ExecutorContext
|
context: ExecutorContext
|
||||||
): Promise<Configuration> {
|
): Promise<Configuration | Configuration[]> {
|
||||||
if (options.isolatedConfig && !options.webpackConfig) {
|
if (options.isolatedConfig && !options.webpackConfig) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Using "isolatedConfig" without a "webpackConfig" is not supported.`
|
`Using "isolatedConfig" without a "webpackConfig" is not supported.`
|
||||||
@ -134,17 +140,32 @@ export async function* webpackExecutor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const configs = await getWebpackConfigs(options, context);
|
const configs = await getWebpackConfigs(options, context);
|
||||||
|
|
||||||
return yield* eachValueFrom(
|
return yield* eachValueFrom(
|
||||||
of(configs).pipe(
|
of(configs).pipe(
|
||||||
switchMap((config) => {
|
mergeMap((config) => (Array.isArray(config) ? from(config) : of(config))),
|
||||||
return runWebpack(config).pipe(
|
// Run build sequentially and bail when first one fails.
|
||||||
tap((stats) => {
|
mergeScan(
|
||||||
console.info(stats.toString(config.stats));
|
(acc, config) => {
|
||||||
})
|
if (!acc.hasErrors()) {
|
||||||
|
return runWebpack(config).pipe(
|
||||||
|
tap((stats) => {
|
||||||
|
console.info(stats.toString(config.stats));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return of();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ hasErrors: () => false } as Stats,
|
||||||
|
1
|
||||||
|
),
|
||||||
|
// Collect build results as an array.
|
||||||
|
bufferCount(Array.isArray(configs) ? configs.length : 1),
|
||||||
|
switchMap(async (results) => {
|
||||||
|
const success = results.every(
|
||||||
|
(result) => Boolean(result) && !result.hasErrors()
|
||||||
);
|
);
|
||||||
}),
|
|
||||||
switchMap(async (result) => {
|
|
||||||
const success = result && !result.hasErrors();
|
|
||||||
return {
|
return {
|
||||||
success,
|
success,
|
||||||
outfile: resolve(
|
outfile: resolve(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user