Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

feat!: disable ssr by default #139

Merged
merged 3 commits into from
May 12, 2021
Merged
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
2 changes: 2 additions & 0 deletions docs/content/en/1.get-started/2.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
},
Expand Down
31 changes: 25 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 = nuxt.options.ssr && 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
Expand Down Expand Up @@ -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
}
}
}
3 changes: 3 additions & 0 deletions test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ export default {
ssrContext.spa = true
}
}
},
vite: {
ssr: true
}
}