Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/nxPublic

Commit2f9978f

Browse files
feat(vite): be able to use a custom build target for the preview server (#14951)
1 parent91117c9 commit2f9978f

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

‎docs/generated/packages/vite/executors/preview-server.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
"clearScreen": {
4242
"description":"Set to false to prevent Vite from clearing the terminal screen when logging certain messages.",
4343
"type":"boolean"
44+
},
45+
"staticFilePath": {
46+
"type":"string",
47+
"description":"Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath",
48+
"x-completion-type":"directory"
4449
}
4550
},
4651
"definitions": {},

‎packages/vite/src/executors/preview-server/preview-server.impl.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,49 @@ import {
99
import{ViteBuildExecutorOptions}from'../build/schema';
1010
import{VitePreviewServerExecutorOptions}from'./schema';
1111

12+
interfaceCustomBuildTargetOptions{
13+
outputPath:string;
14+
}
15+
1216
exportasyncfunction*vitePreviewServerExecutor(
1317
options:VitePreviewServerExecutorOptions,
1418
context:ExecutorContext
1519
){
20+
consttarget=parseTargetString(options.buildTarget,context.projectGraph);
21+
consttargetConfiguration=
22+
context.projectsConfigurations.projects[target.project]?.targets[
23+
target.target
24+
];
25+
if(!targetConfiguration){
26+
thrownewError(`Invalid buildTarget:${options.buildTarget}`);
27+
}
28+
29+
constisCustomBuildTarget=
30+
targetConfiguration.executor!=='@nrwl/vite:build';
31+
1632
// Retrieve the option for the configured buildTarget.
17-
constbuildTargetOptions:ViteBuildExecutorOptions=getNxTargetOptions(
33+
constbuildTargetOptions:
34+
|ViteBuildExecutorOptions
35+
|CustomBuildTargetOptions=getNxTargetOptions(
1836
options.buildTarget,
1937
context
2038
);
2139

40+
constoutputPath=options.staticFilePath??buildTargetOptions.outputPath;
41+
42+
if(!outputPath){
43+
thrownewError(
44+
`Could not infer the "outputPath". It should either be a property of the "${options.buildTarget}" buildTarget or provided explicitly as a "staticFilePath" option.`
45+
);
46+
}
47+
2248
// Merge the options from the build and preview-serve targets.
2349
// The latter takes precedence.
2450
constmergedOptions={
2551
...{watch:{}},
26-
...buildTargetOptions,
52+
...(isCustomBuildTarget ?{} :buildTargetOptions),
2753
...options,
54+
outputPath,
2855
};
2956

3057
// Retrieve the server configuration.
@@ -51,8 +78,9 @@ export async function* vitePreviewServerExecutor(
5178
process.once('exit',processOnExit);
5279

5380
// Launch the build target.
54-
consttarget=parseTargetString(options.buildTarget,context.projectGraph);
55-
constbuild=awaitrunExecutor(target,mergedOptions,context);
81+
// If customBuildTarget is set to true, do not provide any overrides to it
82+
constbuildTargetOverrides=isCustomBuildTarget ?{} :mergedOptions;
83+
constbuild=awaitrunExecutor(target,buildTargetOverrides,context);
5684

5785
forawait(constresultofbuild){
5886
if(result.success){

‎packages/vite/src/executors/preview-server/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export interface VitePreviewServerExecutorOptions {
88
logLevel?:'info'|'warn'|'error'|'silent';
99
mode?:string;
1010
clearScreen?:boolean;
11+
staticFilePath?:string;
1112
}

‎packages/vite/src/executors/preview-server/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
"clearScreen": {
6868
"description":"Set to false to prevent Vite from clearing the terminal screen when logging certain messages.",
6969
"type":"boolean"
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",
74+
"x-completion-type":"directory"
7075
}
7176
},
7277
"definitions": {},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp