Skip to content

Commit 3f9909a

Browse files
fix(web): add option to override outputPath for file-server (#12941)
1 parent 5df5339 commit 3f9909a

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

docs/generated/packages/web.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,10 @@
999999
"type": "boolean",
10001000
"description": "Redirect 404 errors to index.html (useful for SPA's)",
10011001
"default": false
1002+
},
1003+
"staticFilePath": {
1004+
"type": "string",
1005+
"description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath"
10021006
}
10031007
},
10041008
"additionalProperties": false,

packages/web/src/executors/file-server/file-server.impl.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as chalk from 'chalk';
33
import {
44
ExecutorContext,
55
joinPathFragments,
6+
parseTargetString,
7+
readTargetOptions,
68
workspaceLayout,
79
} from '@nrwl/devkit';
810
import ignore from 'ignore';
@@ -57,14 +59,14 @@ function getBuildTargetCommand(options: Schema) {
5759
}
5860

5961
function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) {
62+
if (options.staticFilePath) {
63+
return options.staticFilePath;
64+
}
65+
6066
let buildOptions;
6167
try {
62-
const [project, target, config] = options.buildTarget.split(':');
63-
64-
const buildTarget = context.workspace.projects[project].targets[target];
65-
buildOptions = config
66-
? { ...buildTarget.options, ...buildTarget.configurations[config] }
67-
: buildTarget.options;
68+
const target = parseTargetString(options.buildTarget);
69+
buildOptions = readTargetOptions(target, context);
6870
} catch (e) {
6971
throw new Error(`Invalid buildTarget: ${options.buildTarget}`);
7072
}
@@ -73,7 +75,7 @@ function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) {
7375
const outputPath = buildOptions.outputPath;
7476
if (!outputPath) {
7577
throw new Error(
76-
`Invalid buildTarget: ${options.buildTarget}. The target must contain outputPath property.`
78+
`Unable to get the outputPath from buildTarget ${options.buildTarget}. Make sure ${options.buildTarget} has an outputPath property or manually provide an staticFilePath property`
7779
);
7880
}
7981

packages/web/src/executors/file-server/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export interface Schema {
1212
proxyOptions?: object;
1313
watch?: boolean;
1414
spa: boolean;
15+
staticFilePath?: string;
1516
}

packages/web/src/executors/file-server/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"type": "boolean",
6868
"description": "Redirect 404 errors to index.html (useful for SPA's)",
6969
"default": false
70+
},
71+
"staticFilePath": {
72+
"type": "string",
73+
"description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath"
7074
}
7175
},
7276
"additionalProperties": false,

0 commit comments

Comments
 (0)