Skip to content

Commit

Permalink
fix(angular): resolve build target options correctly in webpack-dev-s…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
leosvelperez committed Mar 13, 2023
1 parent 467be20 commit 69264e9
Showing 1 changed file with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,25 @@ export function executeWebpackDevServerBuilder(
const buildTarget =
browserTargetProjectConfiguration.targets[parsedBrowserTarget.target];

const buildTargetConfiguration = parsedBrowserTarget.configuration
? buildTarget.configurations[parsedBrowserTarget.configuration]
: buildTarget.defaultConfiguration
? buildTarget.configurations[buildTarget.defaultConfiguration]
: buildTarget.options;
const buildTargetOptions = {
...buildTarget.options,
...(parsedBrowserTarget.configuration
? buildTarget.configurations[parsedBrowserTarget.configuration]
: buildTarget.defaultConfiguration
? buildTarget.configurations[buildTarget.defaultConfiguration]
: {}),
};

const buildLibsFromSource =
options.buildLibsFromSource ??
buildTargetConfiguration?.buildLibsFromSource ??
buildTarget.options.buildLibsFromSource ??
buildTargetOptions.buildLibsFromSource ??
true;

const customWebpackConfig: { path: string } =
buildTargetConfiguration?.customWebpackConfig ??
buildTarget.options.customWebpackConfig;

let pathToWebpackConfig: string;
if (customWebpackConfig && customWebpackConfig.path) {
if (buildTargetOptions.customWebpackConfig?.path) {
pathToWebpackConfig = joinPathFragments(
context.workspaceRoot,
customWebpackConfig.path
buildTargetOptions.customWebpackConfig.path
);

if (pathToWebpackConfig && !existsSync(pathToWebpackConfig)) {
Expand All @@ -68,15 +66,11 @@ export function executeWebpackDevServerBuilder(
}
}

const indexFileTransformer: string =
buildTargetConfiguration?.indexFileTransformer ??
buildTarget.options.indexFileTransformer;

let pathToIndexFileTransformer: string;
if (indexFileTransformer) {
if (buildTargetOptions.indexFileTransformer) {
pathToIndexFileTransformer = joinPathFragments(
context.workspaceRoot,
indexFileTransformer
buildTargetOptions.indexFileTransformer
);

if (pathToIndexFileTransformer && !existsSync(pathToIndexFileTransformer)) {
Expand All @@ -88,12 +82,14 @@ export function executeWebpackDevServerBuilder(

let dependencies: DependentBuildableProjectNode[];
if (!buildLibsFromSource) {
const buildTargetTsConfigPath =
buildTargetConfiguration?.tsConfig ?? buildTarget.options.tsConfig;
const { tsConfigPath, dependencies: foundDependencies } =
createTmpTsConfigForBuildableLibs(buildTargetTsConfigPath, context, {
target: parsedBrowserTarget.target,
});
createTmpTsConfigForBuildableLibs(
buildTargetOptions.buildTargetTsConfigPath,
context,
{
target: parsedBrowserTarget.target,
}
);
dependencies = foundDependencies;

// We can't just pass the tsconfig path in memory to the angular builder
Expand All @@ -113,7 +109,7 @@ export function executeWebpackDevServerBuilder(
// otherwise the build will fail if customWebpack function/file is referencing
// local libs. This synchronize the behavior with webpack-browser and
// webpack-server implementation.
buildTargetConfiguration.tsConfig = tsConfigPath;
buildTargetOptions.tsConfig = tsConfigPath;
}

return from(import('@angular-devkit/build-angular')).pipe(
Expand Down Expand Up @@ -146,7 +142,7 @@ export function executeWebpackDevServerBuilder(
return mergeCustomWebpackConfig(
baseWebpackConfig,
pathToWebpackConfig,
buildTargetConfiguration,
buildTargetOptions,
context.target
);
},
Expand All @@ -155,7 +151,7 @@ export function executeWebpackDevServerBuilder(
? {
indexHtml: resolveIndexHtmlTransformer(
pathToIndexFileTransformer,
buildTargetConfiguration.tsConfig,
buildTargetOptions.tsConfig,
context.target
),
}
Expand Down

0 comments on commit 69264e9

Please sign in to comment.