2

我创建了一个库,以便使用 ng-packagr 模块在两个不同的项目之间共享一些组件。

lib的结构是 在此处输入图像描述

在我的图书馆

src/package.json :

{
  "name": "my-ng-library",
  "version": "0.0.0",
  "license": "MIT",
  "ngPackage": {
    "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
    "lib": {
      "entryFile": "index.ts"
    },
    "dest": "../dist"
  },
  "private": false,
  "dependencies": {},
  "peerDependencies": {
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@angular/common": "^5.2.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19",
    "compass-mixins": "^0.12.10"
  }
}

src/components/banner/banner.module.ts:

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

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

src/index.ts:

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

在客户端应用程序中

app.module.ts:

import { BannerModule } from 'my-ng-library/dist';
@NgModule({
  declarations:[
    BannerComponent
  ],
  imports: [
    BannerModule  
  ]
})

一切正常,在本地为应用程序提供服务,但是当我尝试为 prod 构建时,出现以下错误:

错误:由/Users/username/Dev/Work/Essence/app-mobile-network-site/src/app/app.module.ts 中的模块“AppModule”。请添加 @NgModule 注释。

4

0 回答 0