首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角4 AOT编译器

角4 AOT编译器
EN

Stack Overflow用户
提问于 2017-08-21 08:52:02
回答 1查看 856关注 0票数 1

我想为我的应用程序设置AOT编译器。

当我运行node_modules/.bin/ngc -p tsconfig-aot.json时,它会成功编译,不会出现错误。

但是,当我尝试运行ng serve时,它会给出以下错误:

试图找到引导代码,但是找不到。指定静态可分析引导代码或将entryModule传递给插件选项.

代码语言:javascript
复制
Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
    at Object.resolveEntryModuleFromMain (/path/node_modules/@ngtools/webpack/src/entry_resolver.js:128:11)
    at AotPlugin._setupOptions (/path/node_modules/@ngtools/webpack/src/plugin.js:143:50)
    at new AotPlugin (/path/node_modules/@ngtools/webpack/src/plugin.js:26:14)
    at _createAotPlugin (/path/node_modules/@angular/cli/models/webpack-configs/typescript.js:55:12)
    at Object.exports.getNonAotConfig (/path/node_modules/@angular/cli/models/webpack-configs/typescript.js:70:19)
    at NgCliWebpackConfig.buildConfig (/path/node_modules/@angular/cli/models/webpack-config.js:27:37)
    at Class.run (/path/node_modules/@angular/cli/tasks/serve.js:38:98)
    at check_port_1.checkPort.then.port (/path/node_modules/@angular/cli/commands/serve.js:110:26)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

main.ts

代码语言:javascript
复制
import { platformBrowser }    from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/src/app/main/app.module.ngfactory';

console.log('Running AOT compiled');
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-21 09:12:26

node_modules/.bin/ngc -p tsconfig-aot.json将所有文件编译到输出文件夹中。您可以使用任何http服务器从该文件夹运行文件。

然而,在使用angular-cli进行开发时,通常不是这样做的。ng serve使用它自己的不关心output文件夹的开发服务器。如官方文件所述

ng serve构建应用程序并启动web服务器。 ..。以下是其他选项。 - aot

因此,您需要使用--aot选项:

代码语言:javascript
复制
ng serve --aot

而且您不需要修改main.ts文件。它应该有boostrapModule,而不是boostrapModuleFactory方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45792911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档