简体   繁体   English

使用Vue-cli创建的项目部署生产模式

[英]deploying production mode with Vue-cli created project

Bit of a n00b question: I created project with vue-cli using webpack. n00b问题:我使用webpack创建了vue-cli项目。 On my windows machine I run "npm un dev" and I get a frontend server with HMR and so on. 在我的Windows机器上运行“npm un dev”,我得到了一个带HMR的前端服务器,依此类推。 Now I want to deploy my app to a production machine - ubuntu on DigitalOcean. 现在我想将我的应用程序部署到生产机器 - 在DigitalOcean上的ubuntu。

What are the steps I must take? 我必须采取哪些步骤? I'm not very familiar with the logic of how it's supposed to work. 我不太熟悉它应该如何工作的逻辑。 If my ubuntu machine has NODE_ENV set to production, it won't install any of the devDependancies and i'm not able to build anything. 如果我的ubuntu机器将NODE_ENV设置为生产,它将不会安装任何devDependancies,我无法构建任何东西。 So I guess I'll have to change that? 所以我想我必须改变它? If yes then it doesn't make any sense since it's a production machine. 如果是,那么它没有任何意义,因为它是一台生产机器。

And do I have to create another node/express server to serve index.html? 我是否必须创建另一个节点/快速服务器来为index.html提供服务? Won't it supposed to work out-of-the-box somehow? 难道它不应该以某种方式开箱即用吗?

Thanks :) 谢谢 :)

TL;DR Build on your local machine and everything you need will be outputted in the ./dist/ directory, just copy the contents over to the webroot on your production server and you're good to go. TL; DR在您的本地计算机上构建,您需要的所有内容都将在./dist/目录中输出,只需将内容复制到生产服务器上的webroot,就可以了。

The webpack template handles most of the stuff for you. webpack模板为您处理大部分内容。

Step you need to take to release: 您需要采取的步骤:

  1. Run npm run build on your local machine 在本地计算机上运行npm run build
  2. Copy the contents of the generated ./dist/ directory to your server webroot 将生成的./dist/目录的内容复制到服务器webroot
  3. That's it! 而已!

When you run npm run build , the pre-configured build script sets the node environment to production, and builds with only the stuff that should be in production, it also optimizes the code and removes debug capabilities. 当您运行npm run build ,预配置的构建脚本会将节点环境设置为生产环境,并且仅使用应该生产的内容进行构建,它还会优化代码并删除调试功能。 When it comes to dependencies webpack takes care of that and includes them in the generated javascript files located in the ./dist/js/ , so you need not concern yourself with copying over the node_modules/ directory either. 当涉及到依赖关系时,webpack负责处理并将它们包含在./dist/js/生成的javascript文件中,因此您无需关心复制node_modules/目录。 It also copies over everything in your static directory and src/assets directory to the ./dist/ directory to be prepare for a release. 它还将static目录和src/assets目录中的所有内容复制到./dist/目录以准备发布。 And resolves all the references to the new path generated by webpack. 并解析webpack生成的新路径的所有引用。

The production server should not be concerned with building the vue app, run the build command on your local machine to keep dev dependencies away from your production server. 生产服务器不应该关注构建vue应用程序,在本地计算机上运行build命令以使dev依赖性远离生产服务器。 I recommend against installing webpack and other dev tools on your production server. 我建议不要在生产服务器上安装webpack和其他开发工具。 It just pollutes the server with things not needed there. 它只是用那里不需要的东西污染服务器。 Some development tools could potentially produce alot of issues on production servers. 某些开发工具可能会在生产服务器上产生很多问题。 So best practice is to never install them. 所以最好的做法是永远不要安装它们。

You could optionally create your own release script that uses ftp or rsync, whatver you prefer to copy everything in the ./dist/ directory to the production server webroot. 您可以选择创建自己的使用ftp或rsync的发布脚本,无论您希望将./dist/目录中的所有内容复制到生产服务器webroot。 This could be a script in bash, if on windows, run it in git bash or something similar for example. 这可能是bash中的一个脚本,如果在windows上,可以在git bash或类似的东西中运行它。

Hope that cleared things up, congrats on your first vue release! 希望能够解决问题,祝贺你的第一个vue发布!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM