Skip to content

Commit

Permalink
feat(vite): infer continuous tasks for dev (#30043)
Browse files Browse the repository at this point in the history
## Current Behavior
The `dev`, `serve`, `preview` and `serve-static` targets inferred by the
`@nx/vite/plugin` do not infer `continuous:true` indicating to Nx that
these tasks are continuous.


## Expected Behavior
Infer `continuous: true` for the serve-like targets for Vite.
  • Loading branch information
Coly010 authored and FrozenPandaz committed Feb 20, 2025
1 parent 1e6e8ad commit 62dba75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ exports[`@nx/vite/plugin not root project should create nodes 1`] = `
},
"dev": {
"command": "vite",
"continuous": true,
"metadata": {
"description": "Starts Vite dev server",
"help": {
Expand All @@ -143,6 +144,7 @@ exports[`@nx/vite/plugin not root project should create nodes 1`] = `
},
"my-serve": {
"command": "vite",
"continuous": true,
"metadata": {
"deprecated": "Use devTargetName instead. This option will be removed in Nx 22.",
"description": "Starts Vite dev server",
Expand All @@ -164,6 +166,7 @@ exports[`@nx/vite/plugin not root project should create nodes 1`] = `
},
"preview-site": {
"command": "vite preview",
"continuous": true,
"dependsOn": [
"build-something",
],
Expand All @@ -186,6 +189,7 @@ exports[`@nx/vite/plugin not root project should create nodes 1`] = `
},
},
"serve-static": {
"continuous": true,
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build-something",
Expand Down Expand Up @@ -257,6 +261,7 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = `
},
"dev": {
"command": "vite",
"continuous": true,
"metadata": {
"description": "Starts Vite dev server",
"help": {
Expand All @@ -277,6 +282,7 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = `
},
"preview": {
"command": "vite preview",
"continuous": true,
"dependsOn": [
"build",
],
Expand All @@ -300,6 +306,7 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = `
},
"serve": {
"command": "vite",
"continuous": true,
"metadata": {
"deprecated": "Use devTargetName instead. This option will be removed in Nx 22.",
"description": "Starts Vite dev server",
Expand All @@ -320,6 +327,7 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = `
},
},
"serve-static": {
"continuous": true,
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build",
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ describe('@nx/vite/plugin', () => {
},
"dev": {
"command": "vite",
"continuous": true,
"metadata": {
"description": "Starts Vite dev server",
"help": {
Expand All @@ -409,6 +410,7 @@ describe('@nx/vite/plugin', () => {
},
"preview": {
"command": "vite preview",
"continuous": true,
"dependsOn": [
"build",
],
Expand All @@ -432,6 +434,7 @@ describe('@nx/vite/plugin', () => {
},
"serve": {
"command": "vite",
"continuous": true,
"metadata": {
"deprecated": "Use devTargetName instead. This option will be removed in Nx 22.",
"description": "Starts Vite dev server",
Expand All @@ -452,6 +455,7 @@ describe('@nx/vite/plugin', () => {
},
},
"serve-static": {
"continuous": true,
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build",
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ async function buildTarget(

function serveTarget(projectRoot: string, isUsingTsSolutionSetup: boolean) {
const targetConfig: TargetConfiguration = {
continuous: true,
command: `vite`,
options: {
cwd: joinPathFragments(projectRoot),
Expand Down Expand Up @@ -434,6 +435,7 @@ function serveTarget(projectRoot: string, isUsingTsSolutionSetup: boolean) {

function previewTarget(projectRoot: string, buildTargetName) {
const targetConfig: TargetConfiguration = {
continuous: true,
command: `vite preview`,
dependsOn: [buildTargetName],
options: {
Expand Down Expand Up @@ -498,6 +500,7 @@ function serveStaticTarget(
isUsingTsSolutionSetup: boolean
) {
const targetConfig: TargetConfiguration = {
continuous: true,
executor: '@nx/web:file-server',
options: {
buildTarget: `${options.buildTargetName}`,
Expand Down

0 comments on commit 62dba75

Please sign in to comment.