Skip to content

Commit

Permalink
fix(web): add option to override outputPath for file-server (#12941)
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens authored Nov 2, 2022
1 parent 5df5339 commit 3f9909a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/generated/packages/web.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

1 comment on commit 3f9909a

@vercel
Copy link

@vercel vercel bot commented on 3f9909a Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.