Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): add option to override outputPath for file-server #12941

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/generated/packages/web.json
Expand Up @@ -999,6 +999,10 @@
"type": "boolean",
"description": "Redirect 404 errors to index.html (useful for SPA's)",
"default": false
},
"staticFilePath": {
"type": "string",
"description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath"
}
},
"additionalProperties": false,
Expand Down
16 changes: 9 additions & 7 deletions packages/web/src/executors/file-server/file-server.impl.ts
Expand Up @@ -3,6 +3,8 @@ import * as chalk from 'chalk';
import {
ExecutorContext,
joinPathFragments,
parseTargetString,
readTargetOptions,
workspaceLayout,
} from '@nrwl/devkit';
import ignore from 'ignore';
Expand Down Expand Up @@ -57,14 +59,14 @@ function getBuildTargetCommand(options: Schema) {
}

function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) {
if (options.staticFilePath) {
return options.staticFilePath;
}

let buildOptions;
try {
const [project, target, config] = options.buildTarget.split(':');

const buildTarget = context.workspace.projects[project].targets[target];
buildOptions = config
? { ...buildTarget.options, ...buildTarget.configurations[config] }
: buildTarget.options;
const target = parseTargetString(options.buildTarget);
buildOptions = readTargetOptions(target, context);
} catch (e) {
throw new Error(`Invalid buildTarget: ${options.buildTarget}`);
}
Expand All @@ -73,7 +75,7 @@ function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) {
const outputPath = buildOptions.outputPath;
if (!outputPath) {
throw new Error(
`Invalid buildTarget: ${options.buildTarget}. The target must contain outputPath property.`
`Unable to get the outputPath from buildTarget ${options.buildTarget}. Make sure ${options.buildTarget} has an outputPath property or manually provide an staticFilePath property`
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/web/src/executors/file-server/schema.d.ts
Expand Up @@ -12,4 +12,5 @@ export interface Schema {
proxyOptions?: object;
watch?: boolean;
spa: boolean;
staticFilePath?: string;
}
4 changes: 4 additions & 0 deletions packages/web/src/executors/file-server/schema.json
Expand Up @@ -67,6 +67,10 @@
"type": "boolean",
"description": "Redirect 404 errors to index.html (useful for SPA's)",
"default": false
},
"staticFilePath": {
"type": "string",
"description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath"
}
},
"additionalProperties": false,
Expand Down