如何将完成的 nuxt.js 应用程序部署到网络服务器? [英] How to deploy a finished nuxt.js app to a webserver?
问题描述
在工作中,我对 nuxtjs 开发有了一些了解,并且对它非常感兴趣.所以,我开始自己开发一点点,但现在,我被我完成的项目困住了.
At work, I got some little insight to nuxtjs development and I got very interested in it. So, I started developing on my own a little bit, but now, I'm stuck with my finished project.
为了开发,我在 CLI 中使用npm run dev"启动了一个本地服务器.这一切正常.
To develop, I spin up a local server with "npm run dev" in my CLI. This all works fine.
但是,我如何部署我现在完成的项目以在我的家庭服务器上的 nginx 之类的东西中运行它(或者是否有更好的替代方案可以在 Windows Server 环境中运行)?我在 CLI 中听说过npm run build",但除此之外的过程如何?那个命令甚至是正确的方法吗?
But, how do I deploy my now finished project to run it in something like nginx (or are there better alternatives that run on an Windows Server environment) on my home server? I heard about "npm run build" into my CLI, but how is the procedure beyond that? And is that command even the right method?
我绝对是这个部门的菜鸟.有人能一步一步教我做什么才能投入生产"吗?
I'm absolutely a noob in this department. Could anybody teach me step by step what I have to do to go "in production"?
非常感谢!
最大
当然,npm run dev"不是生产的可行选项.它只能从运行服务器的机器上访问.
Of course, "npm run dev" isn't a viable option for production. It's only accessable from the machine the server is running on.
推荐答案
最简单的方法——你需要生成所有内容:
The simplest way - you need to generate all the content:
- 运行
npm run generate
. - 转到项目的
dist
子文件夹,然后将所有内容从那里复制到一些公共托管,例如 GitHub Pages.
- Run
npm run generate
. - Go to the
dist
subfolder of your project and copy all from there to some public hosting, like GitHub Pages.
虽然如果您有一些依赖于用户的内容,您需要将其部署为 SPA:
Though if you have some content depended from the user, you need to deploy it as a SPA:
- 将
nuxt.config.js
中的mode
改为spa
. - 运行
npm run build
. - 将创建的
dist/
文件夹部署到您的静态主机,如 Surge、GitHub Pages 或 nginx.
- Change
mode
innuxt.config.js
tospa
. - Run
npm run build
. - Deploy the created
dist/
folder to your static hostings like Surge, GitHub Pages or nginx.
更多细节:
https://nuxtjs.org/guide/commands#static-生成-部署-预渲染-
https://nuxtjs.org/faq/github-pages#how-to-deploy-on-github-pages-
这篇关于如何将完成的 nuxt.js 应用程序部署到网络服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!