Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/content/docs/1.getting-started/2.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export default defineNuxtConfig({
::field{name="dir" type="string"}
Default to `'.data'` - The directory used for storage (database, kv, cache, etc.) during local development.
::

::field{name="ignoreGenerateWarning" type="boolean"}
Default to `false` - When generating with `nuxi generate` the default behaviour is to exit with an error because NuxtHub is not designed for static hosting.
In certain scenarios it might be desirable to ignore this warning.
::
::

::tip{icon="i-lucide-rocket"}
Expand Down
22 changes: 15 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ export default defineNuxtModule<ModuleOptions>({
},
defaults: {},
async setup(options, nuxt) {
// Cannot be used with `nuxt generate`
if (nuxt.options.nitro.static || (nuxt.options as any)._generate) {
log.error('NuxtHub is not compatible with `nuxt generate` as it needs a server to run.')
log.info('To pre-render all pages: `https://hub.nuxt.com/docs/recipes/pre-rendering#pre-render-all-pages`')
return process.exit(1)
}

const rootDir = nuxt.options.rootDir
const hosting = process.env.NITRO_PRESET || nuxt.options.nitro.preset || provider

const hub = defu(options, {
// Local storage
dir: '.data',
Expand All @@ -49,6 +43,20 @@ export default defineNuxtModule<ModuleOptions>({
// resolve the hub directory
hub.dir = await resolveFs(nuxt.options.rootDir, hub.dir)

// Cannot be used with `nuxt generate`
if (
!hub.ignoreGenerateWarning
&& (nuxt.options.nitro.static || (nuxt.options as any)._generate)
) {
log.error(
'NuxtHub is not compatible with `nuxt generate` as it needs a server to run.'
)
log.info(
'To pre-render all pages: `https://hub.nuxt.com/docs/recipes/pre-rendering#pre-render-all-pages`'
)
return process.exit(1)
}

// Create the hub directory
await mkdir(hub.dir, { recursive: true })
.catch((e: any) => {
Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface HubConfig {
kv: boolean | KVConfig
dir: string
hosting: string
ignoreGenerateWarning: boolean
}

export interface ResolvedHubConfig extends HubConfig {
Expand Down