如何在生产服务器上部署 gulp [英] How to deploy gulp on production server

查看:13
本文介绍了如何在生产服务器上部署 gulp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建网站时(为了清楚起见,仅使用 HTML/JS 的网站),我使用 gulp 编译和连接一些文件,然后将这些文件放在 build/ 文件夹中.

When building a website (for the sake of clarity an HTML/JS only website) I use gulp to compile and concat some files which are then placed in a build/ folder.

文件夹结构如下所示:

├── assets
│   ├── images
│   ├── javascripts
│   │   └── app.js
│   └── stylesheets
│       └── style.scss
├── bower.json
├── build
│   ├── bower_components
│   ├── images
│   ├── index.html
│   ├── scripts.min.js
│   └── styles.min.css
├── gulpfile.js
├── index.html
├── node_modules
│   ├── gulp-module-1
│   └── gulp-module-2
├── package.json
└── README

如果我将所有这些文件包含在一个 git 存储库中,我的所有更改都将提交两次.也就是说:assets/stylesheets/style.scss 的变化也会导致 build/styles.min.css 的变化.但是,如果我决定从存储库中排除 build/ 文件夹,您将需要在生产服务器上使用某些开发工具(即 gulp、npm 等).当权限有限时,这有时会很困难在生产服务器上.显然,排除 assets/ 文件夹不是一种选择,因为您将丢失已编译文件的源代码.

If I include all these files in a git repo, all of my changes will be committed twice. That is: a change in assets/stylesheets/style.scss will also lead to a change in build/styles.min.css. However, if I decide to exclude the build/ folder from the repository, you will need certain development tools on the production server (i.e. gulp, npm, etc.) This can sometimes be difficult when there's limited privileges on the production server. Obviously excluding the assets/ folder is not an option as you will lose the source for your compiled files.

因此我的问题是:在生产服务器上部署它的最佳实践是什么?你是否在 repo 中包含 build/ 文件夹,你是在生产服务器上编译 build/ 文件夹还是有第三种解决方案?

Therefore my question is: what is considered best practice to deploy this on a production server? Do you include the build/ folder in the repo, do you compile the build/ folder on the production server or is there a third solution?

推荐答案

虽然不是每个人都可能同意这个问题的最佳解决方案,但我认为你错过了第三种解决方案,我通常更喜欢它.您可以在开发机器上构建所有文件,然后将构建的文件部署到生产服务器.这通常只是一个复制动作.

Although not everybody might agree on what the best solution is for this problem, I think there is a third solution you have missed and that I would generally prefer. You can build all the files on your development machine, and then deploy the files that were built to your production server. That would usually only be a copy action.

这样您就不需要在您的服务器上安装任何开发工具,并且您的版本控制系统中不会有构建输出.

This way you will not need to have any development tools on your server and you will not have build output in your version control system.

这篇关于如何在生产服务器上部署 gulp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆