标签: angular-jit

基于 angular 9 迁移的 angular 生产问题

大家好,我在迁移后遇到 angular 问题,我已将项目从 angular 8 迁移到 angular 9 。ng server --prod 的角度在第 8 版中有效,但在第 9 版中出现错误。我已经检查过 ng build --prod 和 ng serve --prod。由于新的 angular 9 具有用于 AOT 编译的 IVY 编译器,因此我在 main.ts 中导入了 angular/compiler,而且引导程序正在注入 platformBrowserDynamic,因为我可以看到 angular 8/9 在开发模式下使用 jit 编译进行 ng serve,因此项目是在 jit 上运行,但由于 angular 使用 aot 编译进行生产,我的代码库出错

pollyfills.ts ` import '@angular/compiler'; 导入 '@angular/localize/init'; 导入 'core-js/es/array'; 导入 'zone.js/dist/zone';

`

**main.ts**

`

import '@angular/compiler';
    import { enableProdMode } from '@angular/core';
    import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

    import { AppModule } from './app/app.module'; …
Run Code Online (Sandbox Code Playgroud)

angular2-aot angular angular-jit angular-ivy angular9

7
推荐指数
1
解决办法
3616
查看次数

在 Angular 9 应用中的生产环境中同时使用 AOT 和 JIT

所以我一直在构建一个 Angular 9 应用程序,其中有一个客户仪表板来管理他们保存在服务器上的模板。可以通过激活系统在不同设备上查看这些模板,从而将设备绑定到用户。

所以让https://templates.com我们说我们有/login, /dashboards,/manage带有查看和编辑数据的子路径。在这个 url 上,我们也在/:companyName这个路径上请求一个模板,其中包含带有插值字符串的 html,以及将被动态加载的 css。

到目前为止,由于alarm9k 的帖子,我能够实现这一目标

此解决方案发生的唯一问题是,在构建应用程序时您无法使用,ng build --prod因为 using--prod将不起作用,因为 angular 编译器未包含在 AOT 中,因此您陷入了 JIT。

这将导致一个更大的应用程序,在我的情况下,大小几乎是 42MB。所以我想减小文件大小,因为这会极大地影响应用程序的延迟。我一直在查看应用程序和 atm 的统计信息,它的延迟 http p95 延迟为 1.2 秒,http 平均延迟为 340 毫秒。

当使用不同的网站速度测试并选择英国作为测试应该运行的地方。我得到的加载时间值大约为 600-900 毫秒。检查多个位置时,它给了我 5 秒的平均加载时间。

问题:

所以我想知道是否有办法将应用程序分成 2 个,其中一个处于 AOT 模式,另一个处于 JIT 模式,如果将一部分保持在 JIT 模式下是安全的,并且这是否可以最大限度地减少申请与否。

如果这是不可能的,我想知道最小化此应用程序的最佳方法是什么,以及如何做到这一点。

或者,如果有一种方法至少可以使应用程序更安全,因为在 JIT 模式下可以在浏览器中查看所有代码。

编辑 1:

我忘了提到,在我的情况下,我使用 socket.js 作为激活系统,因此仪表板和模板有些关联。因此,当转到/:companyname并且设备未连接之前,它会自动转到/activate生成代码的位置并侦听用户是否输入该代码,以便将设备连接到用户帐户。

编辑2:

我一直在读到 …

angular angular-aot angular-jit angular9

6
推荐指数
0
解决办法
208
查看次数

Angular 中动态编译的延迟加载动态路由导致“不安全评估”错误

在应用内容安全策略后,在 angular 应用程序的 index.html 文件中,应用程序给出了“unsafe-eval”控制台错误,如下所示 -

core.js:4442 ERROR Error: Uncaught (in promise): EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "default-src 'self'".

EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "default-src 'self'".

    at new Function (<anonymous>)
    at JitEvaluator.evaluateCode (compiler.js:6740)
    at JitEvaluator.evaluateStatements (compiler.js:6714)
    at CompilerFacadeImpl.jitExpression (compiler.js:19300)
    at CompilerFacadeImpl.compileNgModule (compiler.js:19238) …
Run Code Online (Sandbox Code Playgroud)

ivy content-security-policy angular angular-compiler angular-jit

6
推荐指数
1
解决办法
560
查看次数

在 Angular 中使用 JIT 编译比使用 AOT 有什么优势吗?

角文档指定几个原因支持JIT的使用AOT编译:

  • 更快的渲染
  • 更少的异步请求
  • 较小的 Angular 框架下载大小
  • 更早地检测模板错误
  • 更好的安全性

但是,在寻找使用 JIT 的参数时,我没有找到。此外,从 Angular 5.2 升级到 Angular 8 后,我在运行开发构建(使用 JIT)时突然遇到一个奇怪的错误。错误是:

ERROR in ./src/app/shared/app-configuration/shared/app-configuration.model.ts 22:16-35
"export 'IMyComponents' was not found in '@mycompany/mypackage'
Run Code Online (Sandbox Code Playgroud)

运行产品构建(使用 AOT)时,一切正常。这让我感到惊讶,因为我从未遇到过prod 构建成功dev 构建失败的 Angular 编译问题。

所以我的假设是 JIT 只适用于开发构建(即速度)。添加--aot标志可以安全地完成,没有任何问题。或者我错过了什么?

angular angular-aot angular-jit

4
推荐指数
1
解决办法
1163
查看次数