-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
256 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,8 @@ | |
"nx", | ||
"typescript", | ||
"@nx/cypress", | ||
"@nx/playwright" | ||
"@nx/playwright", | ||
"@nx/jest" | ||
] | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Nuxt build executor examples | ||
description: This page contains examples for the @nx/nuxt:build executor. | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Nuxt serve executor examples | ||
description: This page contains examples for the @nx/nuxt:serve executor. | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
{ | ||
"executors": {} | ||
"executors": { | ||
"build": { | ||
"implementation": "./src/executors/build/build.impl", | ||
"schema": "./src/executors/build/schema.json", | ||
"description": "Build with Nuxt." | ||
}, | ||
"serve": { | ||
"implementation": "./src/executors/serve/serve.impl", | ||
"schema": "./src/executors/serve/schema.json", | ||
"description": "Serve with Nuxt." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ExecutorContext, joinPathFragments } from '@nx/devkit'; | ||
import { NuxtBuildExecutorOptions } from './schema'; | ||
|
||
// Required because nuxi is ESM package. | ||
export function loadNuxiDynamicImport() { | ||
return Function('return import("nuxi")')() as Promise<typeof import('nuxi')>; | ||
} | ||
|
||
export async function* nuxtBuildExecutor( | ||
options: NuxtBuildExecutorOptions, | ||
context: ExecutorContext | ||
) { | ||
const projectRoot = | ||
context.projectsConfigurations.projects[context.projectName].root; | ||
const { runCommand } = await loadNuxiDynamicImport(); | ||
try { | ||
await runCommand('build', [projectRoot], { | ||
overrides: { | ||
...options, | ||
workspaceDir: context.root, | ||
buildDir: joinPathFragments(context.root, options.outputPath, '.nuxt'), | ||
nitro: { | ||
output: { | ||
dir: joinPathFragments(context.root, options.outputPath, '.output'), | ||
}, | ||
}, | ||
typescript: { | ||
typeCheck: true, | ||
tsConfig: { | ||
extends: joinPathFragments( | ||
context.root, | ||
projectRoot, | ||
'tsconfig.app.json' | ||
), | ||
}, | ||
}, | ||
imports: { | ||
autoImport: false, | ||
}, | ||
}, | ||
}); | ||
return { success: true }; | ||
} catch (e) { | ||
return { success: false, error: e }; | ||
} | ||
} | ||
|
||
export default nuxtBuildExecutor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { convertNxExecutor } from '@nx/devkit'; | ||
import nuxtBuildExecutor from './build.impl'; | ||
|
||
export default convertNxExecutor(nuxtBuildExecutor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface NuxtBuildExecutorOptions { | ||
debug?: boolean; | ||
dev?: boolean; | ||
ssr?: boolean; | ||
outputPath: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"version": 2, | ||
"outputCapture": "direct-nodejs", | ||
"title": "Nuxt Prod Builder", | ||
"cli": "nx", | ||
"description": "Builds a Nuxt application for production.", | ||
"type": "object", | ||
"presets": [ | ||
{ | ||
"name": "Default minimum setup", | ||
"keys": [] | ||
} | ||
], | ||
"properties": { | ||
"debug": { | ||
"type": "boolean", | ||
"description": "Set to true to enable debug mode." | ||
}, | ||
"dev": { | ||
"type": "boolean", | ||
"description": "Whether Nuxt is running in development mode." | ||
}, | ||
"ssr": { | ||
"type": "boolean", | ||
"description": "Whether to enable rendering of HTML - either dynamically (in server mode) or at generate time. If set to false generated pages will have no content." | ||
}, | ||
"outputPath": { | ||
"type": "string", | ||
"description": "The output path of the generated files.", | ||
"x-completion-type": "directory", | ||
"x-priority": "important" | ||
} | ||
}, | ||
"definitions": {}, | ||
"required": [], | ||
"examplesFile": "../../../docs/build-examples.md" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { convertNxExecutor } from '@nx/devkit'; | ||
import nuxtServeExecutor from './serve.impl'; | ||
|
||
export default convertNxExecutor(nuxtServeExecutor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface NuxtServeExecutorOptions { | ||
debug?: boolean; | ||
dev?: boolean; | ||
ssr?: boolean; | ||
host?: string; | ||
port?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"version": 2, | ||
"outputCapture": "direct-nodejs", | ||
"title": "Nuxt Server", | ||
"cli": "nx", | ||
"description": "Serves a Nuxt application for development.", | ||
"type": "object", | ||
"presets": [ | ||
{ | ||
"name": "Default minimum setup", | ||
"keys": [] | ||
} | ||
], | ||
"properties": { | ||
"debug": { | ||
"type": "boolean", | ||
"description": "Set to true to enable debug mode." | ||
}, | ||
"dev": { | ||
"type": "boolean", | ||
"description": "Whether Nuxt is running in development mode." | ||
}, | ||
"ssr": { | ||
"type": "boolean", | ||
"description": "Whether to enable rendering of HTML - either dynamically (in server mode) or at generate time. If set to false generated pages will have no content." | ||
}, | ||
"port": { | ||
"type": "number", | ||
"description": "Port to listen on.", | ||
"default": 4200 | ||
}, | ||
"host": { | ||
"type": "string", | ||
"description": "Host to listen on.", | ||
"default": "localhost" | ||
} | ||
}, | ||
"definitions": {}, | ||
"required": [], | ||
"examplesFile": "../../../docs/serve-examples.md" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ExecutorContext, joinPathFragments } from '@nx/devkit'; | ||
import { NuxtServeExecutorOptions } from './schema'; | ||
import { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable'; | ||
|
||
// Required because nuxi is ESM package. | ||
export function loadNuxiDynamicImport() { | ||
return Function('return import("nuxi")')() as Promise<typeof import('nuxi')>; | ||
} | ||
|
||
export async function* nuxtServeExecutor( | ||
options: NuxtServeExecutorOptions, | ||
context: ExecutorContext | ||
) { | ||
const projectRoot = | ||
context.projectsConfigurations.projects[context.projectName].root; | ||
yield* createAsyncIterable<{ success: boolean }>(async ({ next, error }) => { | ||
try { | ||
const { runCommand } = await loadNuxiDynamicImport(); | ||
await runCommand('dev', [projectRoot], { | ||
overrides: { | ||
workspaceDir: context.root, | ||
devServer: { | ||
host: options.host, | ||
port: options.port, | ||
}, | ||
typescript: { | ||
typeCheck: true, | ||
tsConfig: { | ||
extends: joinPathFragments( | ||
context.root, | ||
projectRoot, | ||
'tsconfig.app.json' | ||
), | ||
}, | ||
}, | ||
debug: options.debug, | ||
dev: options.dev, | ||
ssr: options.ssr, | ||
}, | ||
}); | ||
next({ | ||
success: true, | ||
}); | ||
} catch (err) { | ||
error(new Error(`Nuxt app exited with message ${err.message}`)); | ||
} | ||
}); | ||
} | ||
|
||
export default nuxtServeExecutor; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.