【问题标题】:How to use third-party components in angular 5 with aot?如何在 Angular 5 中使用第三方组件与 aot?
【发布时间】:2018-01-16 00:50:48
【问题描述】:

该库包括两个文件(在 node_modules/my-lib 中):

  1. some-component.js
  2. some-component.metadata.json

ngc 创建一个工厂:

import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@angular/common";
import * as i3 from "./some-component"; // <--- wtf?

rollup 找不到“./some-component”文件,因为它位于 node_modules/my-lib 中。

早些时候,在 Angular 4 中,工厂是这样创建的:

import * as i0 from '@angular/core';
import * as i1 from '@angular/forms';
import * as i2 from '@angular/common';
import * as i3 from 'my-lib/some-component'; // <--- OK

我的 tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "es2015",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "declaration": false,
        "outDir": "tmp/aot-js",
        "allowJs": true,
        "lib": [
            "es2015",
            "dom"
        ],
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true,
        "typeRoots": [
            "./node_modules/@types/"
        ]
    },
    "files": [
        "src / app / app.module.ts"
    ],
    "angularCompilerOptions": {
        "skipMetadataEmit": false,
        "strictMetadataEmit": false
    },
    "exclude": [
        "node_modules",
        "tmp/**/*",
        "src/main.ts"
    ]
}

现在如何使用第三方库?

【问题讨论】:

  • 我不使用 angular-cli

标签: angular


【解决方案1】:

你必须在 "scripts" 数组下的 .angular-cli.json 文件中声明 JS 组件的路径

【讨论】:

  • 我不使用 angular-cli
猜你喜欢
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 2019-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-24
  • 2019-06-01
相关资源
最近更新 更多