使用node / express / mongo应用程序和打字稿进行连续部署 [英] continuous deployment with node/express/mongo app and typescript

查看:257
本文介绍了使用node / express / mongo应用程序和打字稿进行连续部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从目前为止我所看到的,可以通过创建完全静态的捆绑包(例如,角度包)或通过从仓库中获取源代码并运行 npm install npm开始(通常在使用express / mongo时看到)。

From what I have seen so far, nodejs apps get deployed either by creating a completely static bundle (e.g. angular), or by pulling the source from the repo and running npm install and npm start (usually seen when express/mongo are used).

但是,我正在开发一个express / mongo应用程序与Typescript配对,然后从存储库中提取(需要再次)在生产服务器上构建Typescript,这很丑陋,还需要具有Typescript和所有 @types / * 包作为生产依赖性。所以我想知道:最佳做法是什么?建立&是一个好主意吗?捆绑所有必需的(.js)文件,并将它们与package.json一起推送到服务器,这样我仍然可以运行 npm install 吗? 有什么更好的方法

However, I am developing an express/mongo app paired with typescript, and pulling from the repo would require to build the typescript (again) on the production server, which is ugly and also requires to have typescript and all @types/* packages as production-dependencies. So I was wondering: what are the best practices? Is it a good idea to build & bundle all necessary (.js) files and push them to the server together with package.json, so I can still run npm install? What would be a better way?

推荐答案

您是正确的,不想成为在生产服务器上编译打字稿。通常,在投入生产之前,您需要照顾所有构建和依赖项管理。这意味着创建一个输出独立应用程序进行部署的构建管道。

You are correct that you don't want to be compiling typescript on a production server. Generally, you want to take care of all building and dependency management before you hit production. This means creating a build pipeline that outputs a standalone application for deployment.

典型的构建管道可能如下所示:

A typical build pipeline might look like this:

npm install 棉绒 build 捆绑* .js和node_modules 部署

一个设置这样就可以隔离安装依赖项,更新和构建管道。仅 *。js 文件,已安装的 node_modules 目录和 package.json

A setup like this isolates installing dependencies, linting, and building to the pipeline. Only *.js files, an already installed node_modules directory, and package.json (if it contains the startup script) actually get deployed.

可以通过运行构建脚本并将输出复制到以下位置来手动完成构建管道:code>(如果包含启动脚本)。生产服务器。但是,更好的方法是使用许多可用的构建自动化解决方案之一,例如Jenkins,Travis CI或GitLab CI。

The build pipeline can be done manually, by running a build script and copying the output to the production server. However, a better way is to use one of the many build automation solutions that are available, such as Jenkins, Travis CI, or GitLab CI.

这篇关于使用node / express / mongo应用程序和打字稿进行连续部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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