From 9741f267be1c04a69f3a25204c175f98d834565b Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 26 Jul 2023 23:07:23 +0200 Subject: [PATCH] refactor(nuxi,schema): move loading template into schema (#22336) --- packages/nuxi/src/commands/dev.ts | 2 +- packages/nuxt/package.json | 2 +- packages/schema/package.json | 1 + packages/schema/src/config/dev.ts | 8 ++++++++ pnpm-lock.yaml | 11 +++++++---- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index 50e10e99ae..9da83dc685 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -46,7 +46,7 @@ export default defineNuxtCommand({ let currentHandler: RequestListener | undefined let loadingMessage = 'Nuxt is starting...' const loadingHandler: RequestListener = async (_req, res) => { - const { loading: loadingTemplate } = await importModule('@nuxt/ui-templates', config.modulesDir) + const loadingTemplate = config.devServer.loadingTemplate ?? await importModule('@nuxt/ui-templates', config.modulesDir).then(r => r.loading) res.setHeader('Content-Type', 'text/html; charset=UTF-8') res.statusCode = 503 // Service Unavailable res.end(loadingTemplate({ loading: loadingMessage })) diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 6a14d21b27..18599013bd 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -56,7 +56,7 @@ "@nuxt/kit": "workspace:../kit", "@nuxt/schema": "workspace:../schema", "@nuxt/telemetry": "^2.3.2", - "@nuxt/ui-templates": "^1.2.0", + "@nuxt/ui-templates": "^1.2.1", "@nuxt/vite-builder": "workspace:../vite", "@unhead/ssr": "^1.1.32", "@unhead/vue": "^1.1.32", diff --git a/packages/schema/package.json b/packages/schema/package.json index d2edcf46b3..30edc67a79 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -49,6 +49,7 @@ "webpack-dev-middleware": "6.1.1" }, "dependencies": { + "@nuxt/ui-templates": "^1.2.1", "defu": "^6.1.2", "hookable": "^5.5.3", "pathe": "^1.1.1", diff --git a/packages/schema/src/config/dev.ts b/packages/schema/src/config/dev.ts index e56860fa86..5f46df1949 100644 --- a/packages/schema/src/config/dev.ts +++ b/packages/schema/src/config/dev.ts @@ -1,4 +1,5 @@ import { defineUntypedSchema } from 'untyped' +import { loading as loadingTemplate } from '@nuxt/ui-templates' export default defineUntypedSchema({ devServer: { @@ -36,5 +37,12 @@ export default defineUntypedSchema({ * dev server with the full URL (for module and internal use). */ url: 'http://localhost:3000', + + /** + * Template to show a loading screen + * + * @type {(data: { loading?: string }) => string} + */ + loadingTemplate: loadingTemplate } }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dae2864423..e9836020a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -347,8 +347,8 @@ importers: specifier: ^2.3.2 version: 2.3.2 '@nuxt/ui-templates': - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^1.2.1 + version: 1.2.1 '@nuxt/vite-builder': specifier: workspace:* version: link:../vite @@ -521,6 +521,9 @@ importers: packages/schema: dependencies: + '@nuxt/ui-templates': + specifier: ^1.2.1 + version: 1.2.1 defu: specifier: ^6.1.2 version: 6.1.2 @@ -2075,8 +2078,8 @@ packages: rc9: 2.1.1 std-env: 3.3.3 - /@nuxt/ui-templates@1.2.0: - resolution: {integrity: sha512-MSZza7dxccNb/p7nuzGF8/m4POaFpHzVhNdR7f4xahOpH7Ja02lFeYR+rHtoHIJC0yym4qriqv0mQ+Qf/R61bQ==} + /@nuxt/ui-templates@1.2.1: + resolution: {integrity: sha512-Nt1nTkPsji/X8z/BCqUgb8uADs+kT0FZboVDwyCdMlCgjEQKrAZUlunKXGywa6ssz4/RohGmvuB1cFre6dSKXQ==} dev: false /@nuxtjs/eslint-config-typescript@12.0.0(eslint@8.45.0)(typescript@5.0.4):