From a6dbc89aae60718e66264c5f9e7ba1570f8295e2 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 12 May 2021 11:54:21 +0200 Subject: [PATCH 1/3] feat!: disable ssr by default --- src/index.ts | 31 +++++++++++++++++++++++++------ test/fixture/nuxt.config.js | 3 +++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3d80e81..9793622 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ import type { } from '@nuxt/types' import { resolve } from 'upath' +import consola from 'consola' import { lt } from 'semver' import { name, version } from '../package.json' import type { ViteOptions } from './types' @@ -16,16 +17,31 @@ function nuxtVite () { const currentVersion = nuxt.constructor.version || '0.0.0' if (lt(nuxt.constructor.version, minVersion)) { // eslint-disable-next-line no-console - console.warn(`disabling nuxt-vite since nuxt >= ${minVersion} is required (curret version: ${currentVersion})`) + consola.warn(`disabling nuxt-vite since nuxt >= ${minVersion} is required (curret version: ${currentVersion})`) return } + // Disable SSR by default + const ssrEnabled = Boolean(nuxt.options.vite?.ssr) + if (!ssrEnabled) { + nuxt.options.ssr = false + nuxt.options.render.ssr = false + nuxt.options.build.ssr = false + nuxt.options.mode = 'spa' + } + nuxt.options.cli.badgeMessages.push(`⚡ Vite Mode Enabled (v${version})`) // eslint-disable-next-line no-console - console.log( - '🧪 Vite mode is experimental and many nuxt modules are still incompatible\n', - ' If found a bug, please report via https://github.com/nuxt/vite/issues with a minimal reproduction' - ) + if (nuxt.options.vite?.experimentWarning !== false && !nuxt.options.test) { + consola.log( + '🧪 Vite mode is experimental and some nuxt modules might be incompatible\n', + ' If found a bug, please report via https://github.com/nuxt/vite/issues with a minimal reproduction.' + ( + ssrEnabled + ? '\n Unstable server-side rendering is enabled' + : '\n You can enable unstable server-side rendering using `vite: { ssr: true }` in `nuxt.config`' + ) + ) + } // Disable loading-screen because why have it! nuxt.options.build.loadingScreen = false @@ -74,6 +90,9 @@ declare module '@nuxt/types/config/index' { * * @link https://vitejs.dev/config/ */ - vite?: ViteOptions + vite?: ViteOptions & { + ssr: false | ViteOptions['ssr'], + experimentWarning: boolean + } } } diff --git a/test/fixture/nuxt.config.js b/test/fixture/nuxt.config.js index b31827a..4a9e2b2 100644 --- a/test/fixture/nuxt.config.js +++ b/test/fixture/nuxt.config.js @@ -22,5 +22,8 @@ export default { ssrContext.spa = true } } + }, + vite: { + ssr: true } } From 761d55cc5c61e336a6738f19b43af571961e5817 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 12 May 2021 12:01:07 +0200 Subject: [PATCH 2/3] fix: handle --spa flag (ssr disabled regardless of vite) --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 9793622..48ca614 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ function nuxtVite () { } // Disable SSR by default - const ssrEnabled = Boolean(nuxt.options.vite?.ssr) + const ssrEnabled = nuxt.options.ssr && nuxt.options.vite?.ssr if (!ssrEnabled) { nuxt.options.ssr = false nuxt.options.render.ssr = false From 7788d4859340bf4b1646b2bb6ee732d366098a37 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 12 May 2021 12:25:12 +0200 Subject: [PATCH 3/3] chore: update docs --- docs/content/en/1.get-started/2.config.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/content/en/1.get-started/2.config.md b/docs/content/en/1.get-started/2.config.md index 03a746e..464e4d6 100644 --- a/docs/content/en/1.get-started/2.config.md +++ b/docs/content/en/1.get-started/2.config.md @@ -15,6 +15,8 @@ export default { ], vite: { /* options for vite */ + // ssr: true // enable unstable server-side rendering for development (false by default) + // experimentWarning: false // hide experimental warning message (disabled by default for tests) vue: { /* options for vite-plugin-vue2 */ },