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

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

问题描述

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



文件夹结构如下所示:

 ├ ──资产
│├──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等)。在生产服务器上的权限有限时很难实现。显然,排除资产/ 文件夹不是一个选项,因为您将失去编译文件的源代码。

因此,

我的问题是:什么被认为是在生产服务器上部署它的最佳实践?您是否在回购库中包含 build / 文件夹,您是否在生产服务器上编译 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.

The folder structure looks something like this:

├── 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

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.

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天全站免登陆