无法使用ng-packagr正确实现Angular库

时间:2018-06-18 13:43:05

标签: javascript angular angular5 ng-packagr

关于如何使用 ng-packagr 创建Angular库后tutorial,我仍然坚持使用它。

我有这个错误

   ./src/app/app.module.ts中的错误   找不到模块:错误:无法解析' ../../ node_modules / my-ng-library / dist / public_api' in' / Users / username / Dev / my-mobile-network-site-frontend / src / app'

文件夹结构是经典的,我使用主 package.json 来包含

"ngPackage": {
    "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
    "lib": {
      "entryFile": "public_api.ts"
    },
    "dest": "dist"
  },

运行 ng-packagr -p package.json 后,一切都很顺利得到像这样的/ dist文件夹 enter image description here

public_api.d.ts

export { BannerModule } from './src/app/components/banner/banner.module';
export { BannerComponent } from './src/app/components/banner/banner.component';

源模块是:

import { BannerComponent } from './banner.component';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
    CommonModule
  ],
  exports: [
    BannerComponent
  ],
  declarations: [BannerComponent],
  providers: []
})
export class BannerModule { }

同样在我想要使用此库中的组件的项目中,我需要像这样导入(否则我得到另一个关于找不到模块的错误)

import { BannerModule } from '../../node_modules/my-ng-library/dist/my-ng-library';

0 个答案:

没有答案