Skip to content

Commit db14994

Browse files
committed
(ssr) migrate nuxt config & setup
1 parent 079ffa3 commit db14994

File tree

7 files changed

+40
-69
lines changed

7 files changed

+40
-69
lines changed

examples/nuxt/layouts/default.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<Nuxt />
3+
<slot />
44
</div>
55
</template>
66

examples/nuxt/nuxt.config.js

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,15 @@
1-
export default {
2-
/*
3-
** Nuxt rendering mode
4-
** See https://nuxtjs.org/api/configuration-mode
5-
*/
6-
mode: 'universal',
7-
/*
8-
** Nuxt target
9-
** See https://nuxtjs.org/api/configuration-target
10-
*/
11-
target: 'server',
12-
/*
13-
** Headers of the page
14-
** See https://nuxtjs.org/api/configuration-head
15-
*/
16-
head: {
17-
title: process.env.npm_package_name || '',
18-
meta: [
19-
{ charset: 'utf-8' },
20-
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
21-
{
22-
hid: 'description',
23-
name: 'description',
24-
content: process.env.npm_package_description || '',
25-
},
26-
],
27-
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
1+
import { defineNuxtConfig } from 'nuxt/config'
2+
3+
export default defineNuxtConfig({
4+
compatibilityDate: '2025-05-23',
5+
devServer: {
6+
host: '::1'
287
},
29-
/*
30-
** Global CSS
31-
*/
32-
css: [],
33-
/*
34-
** Plugins to load before mounting the App
35-
** https://nuxtjs.org/guide/plugins
36-
*/
37-
plugins: ['~/plugins/vue-js-modal.js'],
38-
/*
39-
** Auto import components
40-
** See https://nuxtjs.org/api/configuration-components
41-
*/
42-
components: true,
43-
/*
44-
** Nuxt.js dev-modules
45-
*/
46-
buildModules: [
47-
// Doc: https://github.com/nuxt-community/eslint-module
48-
'@nuxtjs/eslint-module',
8+
ssr: process.env.NUXT_RENDERING_MODE !== 'csr',
9+
plugins: [
10+
process.env.NUXT_RENDERING_MODE === 'csr'
11+
? '~/plugins-no-auto-import/vue-js-modal-csr.js'
12+
: '~/plugins-no-auto-import/vue-js-modal-ssr.js'
4913
],
50-
/*
51-
** Nuxt.js modules
52-
*/
53-
modules: [],
54-
/*
55-
** Build configuration
56-
** See https://nuxtjs.org/api/configuration-build/
57-
*/
58-
build: {},
59-
}
14+
modules: ['@nuxt/eslint']
15+
})

examples/nuxt/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
"version": "1.0.0",
44
"private": true,
55
"scripts": {
6-
"dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider nuxt",
7-
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider nuxt build",
8-
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider nuxt start",
9-
"export": "cross-env NODE_OPTIONS=--openssl-legacy-provider nuxt export",
10-
"serve": "cross-env NODE_OPTIONS=--openssl-legacy-provider nuxt serve",
6+
"dev:ssr": "cross-env NODE_OPTIONS=--openssl-legacy-provider NUXT_RENDERING_MODE=ssr nuxt dev --open",
7+
"build:ssr": "cross-env NODE_OPTIONS=--openssl-legacy-provider NUXT_RENDERING_MODE=ssr nuxt build",
8+
"dev:csr": "cross-env NODE_OPTIONS=--openssl-legacy-provider NUXT_RENDERING_MODE=csr nuxt dev --open",
9+
"build:csr": "cross-env NODE_OPTIONS=--openssl-legacy-provider NUXT_RENDERING_MODE=csr nuxt build",
1110
"lint:js": "eslint --ext .js,.vue --ignore-path .gitignore .",
1211
"lint": "yarn lint:js"
1312
},

examples/nuxt/pages/index.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<div class="links">
1010
<button class="button--green" @click="click">Show modal</button>
1111
</div>
12+
<p style="margin-top: 40px">{{ renderMode }}</p>
1213
</div>
1314
</div>
1415
</template>
@@ -20,6 +21,13 @@ export default {
2021
components: {
2122
ExampleModal
2223
},
24+
computed: {
25+
renderMode() {
26+
return this.$nuxt.payload.serverRendered
27+
? 'Server-Side Rendering'
28+
: 'Client-Side Rendering'
29+
}
30+
},
2331
methods: {
2432
click() {
2533
this.$modal.show('example-modal')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineNuxtPlugin } from 'nuxt/app'
2+
import Modal from '../../../dist/ssr.index'
3+
4+
export default defineNuxtPlugin((nuxtApp) => {
5+
nuxtApp.vueApp.use(Modal)
6+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineNuxtPlugin } from 'nuxt/app'
2+
import Modal from '../../../dist/ssr.nocss'
3+
4+
import '../../../dist/styles.css'
5+
6+
export default defineNuxtPlugin((nuxtApp) => {
7+
nuxtApp.vueApp.use(Modal)
8+
})

examples/nuxt/plugins/vue-js-modal.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)