简体   繁体   English

带角度cli进行生产时需要打字稿吗?

[英]Typescript required for taking build in production with angular cli?

I have developed Angular 4 based application and providing the source file to build team and they have NodeJS and Angular CLI, could TypeScript required to build the source code in production with their machine? 我已经开发了基于Angular 4的应用程序,并提供了构建团队所需的源文件,他们拥有NodeJS和Angular CLI,TypeScript可能需要使用其机器在生产环境中构建源代码吗?

for ng build--prod 用于ng build--prod

This is rather unclear but I will try my best to answer (from what I have understood on my own). 这还不太清楚,但是我会尽力回答(根据我自己的理解)。

When you create an Angular project with the CLI, it installs all the required dependencies, such as Typescript, or SASS, for instance. 使用CLI创建Angular项目时,它将安装所有必需的依赖项,例如Typescript或SASS。

When you build your application, you again type in the command ng build : this means you are actually using the CLI to build your application. 在构建应用程序时,再次输入ng build命令:这意味着您实际上是在使用CLI来构建应用程序。 The same CLI that has already installed all the required dependencies. 已安装所有必需依赖项的同一CLI。

So, if you want to know if you need to install typescript as a global package, the answer is no. 因此,如果您想知道是否需要将Typescript作为全局软件包安装,答案是否定的。 If you mean you need to install typescript as an application dependency, then the answer is yes. 如果您的意思是需要将Typescript安装为应用程序依赖项,那么答案是肯定的。

In the end, all you need to do to deploy your app (or for your coworkers to deploy it), is the source code, and a global installation of the CLI. 最后,您要做的就是部署应用程序(或让您的同事部署应用程序),源代码和CLI的全局安装。

I hope this helps ! 我希望这有帮助 !

Let me give you example of our usage of angular in production environment. 让我举一个例子,说明我们在生产环境中使用角度的情况。

In our local machines, we have npm and angular-cli (global) installed, and once we are done with development, we merge our code into the repository and use jenkins build jobs to build our code. 在本地计算机中,我们安装了npm和angular-cli(全局),完成开发后,我们将代码合并到存储库中,并使用jenkins构建作业来构建代码。 However, there may be other teams who use the same jenkins machine to build their own code and we may have different angular-cli version dependecies. 但是,可能还有其他团队使用相同的詹金斯机器来构建自己的代码,并且我们可能有不同的angular-cli版本依赖关系。 Let's say our project uses angular-cli v1.5.4, and theirs use angular-cli v1.4. 假设我们的项目使用angular-cli v1.5.4,而他们的项目使用angular-cli v1.4。 It would be a bad idea to install global angular-cli in the build machine. 在构建机器中安装全局angular-cli是一个坏主意。 However, to run ng build --prod command, you need to have a globally installed angular-cli. 但是,要运行ng build --prod命令,您需要全局安装一个angular-cli。

Instead of this, you should always build your code with npm run build command which will trigger the build script written in your package.json . 取而代之的是,您应该始终使用npm run build命令来构建代码,这将触发在package.json编写的build脚本。 This way, you don't need to have an globally installed angular-cli, npm will use local angular-cli within your project so that every team can build their code with different versions of angular-cli. 这样,您不需要全局安装的angular-cli,npm将在您的项目中使用本地angular-cli,这样每个团队都可以使用不同版本的angular-cli构建其代码。

Hope this clarifies your question. 希望这可以澄清您的问题。

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

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