【问题标题】:How to avoid loading node_modules and .ts files on production mode in angular 4 with Visual Studio 2017如何避免使用 Visual Studio 2017 在 Angular 4 的生产模式下加载 node_modules 和 .ts 文件
【发布时间】:2018-12-15 19:33:47
【问题描述】:

我的项目是建立在 angular 4 over asp.net mvc(VS2017) 上的。在生产模式下,所有 *.ts 文件和节点模块都加载到浏览器,我如何避免在最终版本中将 *.ts 文件和 node_module 文件夹加载到浏览器。

【问题讨论】:

标签: angular visual-studio-2017 node-modules


【解决方案1】:

您必须使用 ng build --prod 构建 Angular 应用程序。


这将编译应用程序并压缩和缩小所有文件。事实上,.ts 文件此时已转换为.js 文件。

ng build --prod 采用 AOT(Ahead of Time)技术,这意味着在加载应用程序之前,它已经提前编译。

ng serve 采用 JIT(即时)技术,浏览器在运行时编译 .ts 文件。


有关 Angular CLI 在构建时采取的某些优势/步骤的更多信息,请参阅以下 URL:-

https://angular.io/guide/deployment#build-with---prod

有关 Angular 编译器的更多信息以及可用于编译的各种选项,您还可以参考以下帖子:-

https://angular.io/guide/aot-compiler

【讨论】:

    猜你喜欢
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    相关资源
    最近更新 更多