【问题标题】:What does false do in aot build angular cli - Out of memory issuefalse 在 aot build angular cli 中做了什么 - 内存不足问题
【发布时间】:2018-04-08 00:04:18
【问题描述】:

"false"ng build --prod --aot false 命令中做了什么

我正在开发一个使用 ng cli 开发的 Angular 4 应用程序,因为它是一个企业解决方案,应用程序变得如此庞大以至于需要花费太多时间来服务和构建。我什至遇到了 javascript 内存不足的问题,我开始使用以下命令来构建应用程序

ng build --prod --aot false

但我不确定它是如何工作的

【问题讨论】:

  • 你在哪里看到的?
  • 我在其中一个 stackoverflow 线程中看到它,如果我在没有 false 的情况下运行命令,它会给我内存不足错误,所以肯定会产生一些影响
  • 这里没什么好玩的,你提前关掉编译
  • @yurzui,很高兴知道。所以它基本上是--aot 选项的值?相反的是--aot true?
  • 如果我们使用--prod,我们已经有--aot true 有一个很棒的链接关于这个github.com/angular/angular-cli/blob/master/docs/documentation/…

标签: angular build


【解决方案1】:

对于生产版本,AOT 默认为 true,如果您想停用,可以使用:

ng build prod --no-aot 

ng build prod --aot=false

但是使用 AOT 会在提供模板之前将模板编译为 js,因此浏览器会非常快速地加载它们

【讨论】:

    【解决方案2】:

    所有可用的 angular-cli 命令都可以在 here 找到。

    现在,当我们运行ng build --prod 时,这意味着我们为我们的应用程序指定了target

    {
        name: 'target',
        type: String,
        default: 'development',
        aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }],
        description: 'Defines the build target.'
    },
    

    然后 angular-cli sets default options(angular-cli@1.4.x) 基于指定目标:

    // Fill in defaults for build targets
    public addTargetDefaults(buildOptions: T): T {
      const targetDefaults: { [target: string]: Partial<BuildOptions> } = {
        development: {
          environment: 'dev',
          outputHashing: 'media',
          sourcemaps: true,
          extractCss: false,
          namedChunks: true,
          aot: false
        },
        production: {
          environment: 'prod',
          outputHashing: 'all',
          sourcemaps: false,
          extractCss: true,
          namedChunks: false,
          aot: true
        }
      };
    

    也可以在docs中找到

    当您添加 --aot false 时,您会覆盖默认的 aot 选项。所以它变成了false

    如果您在构建 aot 时遇到问题,那么有 some thread 用于常见解决方案正在运行构建的地方,例如:

    package.json

    "scripts": {
      "prod": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --prod" 
    }
    

    但除此之外,我更喜欢做一些重构代码以减小应用程序大小并帮助 aot 编译器更快地执行。

    【讨论】:

      猜你喜欢
      • 2018-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 2011-07-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多