英文:
does using nuxt with `ssr: false` makes nuxt same as regular vue with nodejs hosting?
问题
如果您在nuxt.config.js
文件中设置ssr: false
,这是否使Nuxt的工作方式与普通的Vue应用程序完全相同?
如果是这样的话,运行npm run build
,npm run start
只会使用Node.js服务器提供静态的HTML/CSS/JS文件,对吗?
英文:
if you set ssr: false
in nuxt.config.js
file, does this make nuxt work exactly same as plain Vue application?
if so, doing npm run build
, npm run start
will just serve static html/css/js file with node.js server?
Am I right here?
答案1
得分: 1
从nuxt3 文档
ssr - 禁用应用程序的某些部分的服务器端渲染,使它们仅支持SPA,设置为 ssr: false
根据文档的理解
当SSR为false并使用npm run build
时
如果将ssr: false
设置并构建项目而不生成它,那么它将像一个简单的Vue SPA应用程序一样运行。就像传统的SPA应用程序一样,在初始加载时它将加载整个JavaScript文件,然后在客户端进行渲染。
当SSR为false并使用npm run generate
时
同样,如果将ssr: false
设置并生成项目而不构建它,那么它将预渲染所有页面并生成静态文件。它将像传统的静态网站一样运行。 但请注意,由于SSR为false,它不会在生成时预取所需的任何数据。因此,最好在SSR模式下生成页面。
英文:
From the nuxt3 document
> ssr - Disables server-side rendering for sections of your app and make them SPA-only with ssr: false
What I understand from the doc
When SSR is false and use npm run build
If you make ssr: false
and build the project not generate, then It will work like a simple vue spa application. Like a traditional spa application, it will load the whole js in the initial load and then render in the client site.
When SSR is false and use npm run generate
Again if you make ssr: false
and generate the project not build, Then it will prerender all the pages and generate the static file. And it will work like a traditional static website. But you have to be careful that as SSR is false it will not prefetch any data it needs in the generated time. So It's best to generate pages with SSR mode on.
答案2
得分: 1
Yeah, that will make Nuxt behave like Vue for the rendering part.
Be sure to have generate
for an SSG target and not build
(for SSR).
Here are more details of the benefits of still using Nuxt: link
If you're doing npm run build
, it's supposing that you're using your Nuxt app as SSR. Which means pretty much nothing since you don't want SSR (false
).
It's like saying
I want a tomato sandwich, but without the tomato.
In the current situation, Nuxt3 will probably give you a sandwich but without tomatoes aka SPA-only
Nuxt3 generated as SSG. Totally hostable as any other regular SPA app, on Netlify.
Official source: link
Also, what Nuxt is doing during local development and on production are 2 different things.
You will always have a Node.js server running for dev, but that is not the case once deployed (SSG, SPA, etc...).
If you want a Nuxt3 SSR'ed app, use build
+ ssr: true
.
英文:
Yeah, that will make Nuxt behave like Vue for the rendering part.
Be sure to have generate
for an SSG target and not build
(for SSR).
Here are more details of the benefits of still using Nuxt: https://stackoverflow.com/a/74714106/8816585
If you're doing npm run build
, it's supposing that you're using your Nuxt app as SSR. Which means pretty much nothing since you don't want SSR (false
).
It's like saying
> I want a tomato sandwich, but without the tomato.
In the current situation, Nuxt3 will probably give you a sandwich but without tomatoes aka SPA-only
Nuxt3 generated as SSG. Totally hostable as any other regular SPA app, on Netlify.
Official source: https://nuxt.com/docs/getting-started/deployment#client-side-only-rendering
Also, what Nuxt is doing during local development and on production are 2 different things.
You will always have a Node.js server running for dev, but that is not the case once deployed (SSG, SPA, etc...).
If you want a Nuxt3 SSR'ed app, use build
+ ssr: true
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论