[英]Is it mandatory for each deployment to production for remove node modules and run npm install?
I use vuetify (vue)我使用 vuetify (vue)
Is it mandatory for each deployment to production for remove node modules and run npm install
?每次部署到生产是否都必须删除节点模块并运行
npm install
? Or just run npm run build
?或者只是运行
npm run build
?
I have two option :我有两个选择:
Option 1 : Every deployment, I run the npm run build
directly选项 1:每次部署,我都直接运行
npm run build
Option 2 :选项2:
npm install
npm run build
Which is the best option?哪个是最好的选择?
This command installs a package, and any packages that it depends on.
此命令安装一个包,以及它所依赖的任何包。 If the package has a package-lock or shrinkwrap file, the installation of dependencies will be driven by that, with an npm-shrinkwrap.json taking precedence if both files exist.
如果包有 package-lock 或 shrinkwrap 文件,依赖项的安装将由它驱动,如果两个文件都存在,则 npm-shrinkwrap.json 优先。 See package-lock.json and npm-shrinkwrap .
请参阅package-lock.json和npm- shrinkwrap 。
If you did not install or update the package before releasing the project, you do not need to execute npm install
, otherwise, you need to execute it to ensure that dependent packages on the production environment is consistent with your local dependent package version.如果您在发布项目之前没有安装或更新包,则不需要执行
npm install
,否则需要执行它以确保生产环境中的依赖包与您本地的依赖包版本一致。
If you are using an automatic build deployment tool like jenkins, for convenience you can execute the install command before each build.如果您使用像 jenkins 这样的自动构建部署工具,为方便起见,您可以在每次构建之前执行 install 命令。 It's okay.
没关系。
Imagine more environments, not just a production:想象更多的环境,而不仅仅是生产:
Can we upload the npm run build
result (compressed js) or node_modules to our git repository?我们可以将
npm run build
结果(压缩的 js)或node_modules 上传到我们的 git 存储库吗? ANSWER IS NOT!!答案不是!! .
. So if you need to have a version of your app running in any of these environments, you must to execute
npm run build
.因此,如果您需要在任何这些环境中运行某个版本的应用程序,则必须执行
npm run build
。 And this command needs the classic npm run install
.这个命令需要经典的
npm run install
。 I think this last sentence, answer your question.我想这最后一句话,回答你的问题。
assumption 1 your client-side app (vue) is not complex(no login, no session, no logout, etc ), you could publish it using a basic nginx, apache, basic-nodejs .假设 1您的客户端应用程序 (vue) 并不复杂(没有登录、没有会话、没有注销等),您可以使用基本的 nginx、apache、 basic-nodejs发布它。
assumption 2 you are able to have one more server for docker private repository .假设 2您可以为docker 私有存储库多拥有一台服务器。 Also if you are in google, amazon o azure, this service is ready to use, of course a payment is required
另外如果你在google、amazon o azure,这个服务就可以使用了,当然是需要付费的
In one line, with docker you must execute just one time npm install and npm run build .一方面,使用 docker,您必须只执行一次npm install和npm run build 。 Complete flow is:
完整的流程是:
If your quality assurance team needs to perform some tests to your new app, just a docker image download is required.如果您的质量保证团队需要对您的新应用程序执行一些测试,则只需要下载 docker 映像。 If everything is ok, you pass to the next stage (staging or uat) or production.
如果一切正常,您将进入下一阶段(登台或 uat)或生产。 Steps will be the same: just download the docker image.
步骤相同:只需下载 docker 镜像。
In this case, nginx or apache does not helps you because they are a simple static servers.在这种情况下,nginx 或 apache 对您没有帮助,因为它们是简单的静态服务器。
You could use a minimal nodejs code like this:您可以使用这样的最小 nodejs 代码:
https://github.com/jrichardsz/nodejs-static-pages/blob/master/server.js https://github.com/jrichardsz/nodejs-static-pages/blob/master/server.js
Adding /login , /logout, etc添加 /login 、 /logout 等
Or use my server:或者使用我的服务器:
https://github.com/utec/geofrontend-server https://github.com/utec/geofrontend-server
which has a /login, /logout and other cool features for example: How are you planning to pass your backend api urls to your vue app in any of your environments?.它具有 /login、/logout 和其他很酷的功能,例如:您打算如何在您的任何环境中将后端 api url 传递给您的 vue 应用程序?。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.