Exporting UI-Components in Angular 5 - template not found

自古美人都是妖i 提交于 2019-12-25 12:50:46

问题


I'm developing UI Components for usage in different Web-Projects across the company. We want to publish the ui-components as npm package on our local Repository. Publishing the package works fine.

When I npm install the package, import the module in my app.module.ts and run 'ng serve' (it's an Angular CLI Project), everything compiles fine. But when accessing the Site on localhost, nothing is shown and the console says:

Why is Angular looking for templates in html format, when they are compiled and packaged? And how to tell the CLI that these components are already compiled?


tsconfig.json (before packaging)

{
   "compilerOptions": {
      "baseUrl": ".",
      "declaration": true,
      "stripInternal": true,
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "strictNullChecks": true,
      "noImplicitAny": true,
      "module": "es2015",
      "moduleResolution": "node",
      "paths": {
         "@angular/core": ["node_modules/@angular/core"],
         "@angular/common": ["node_modules/@angular/common"],
         "@angular/forms": ["node_modules/@angular/forms"],
         "@ng-bootstrap/ng-bootstrap": ["node_modules/@ng-bootstrap/ng-bootstrap"]
      },
      "rootDir": ".",
      "outDir": "dist",
      "sourceMap": true,
      "inlineSources": true,
      "target": "es5",
      "skipLibCheck": true,
      "lib": [
         "es2015",
         "dom"
      ]
   },
   "files": [
      "index.ts"
   ],
   "angularCompilerOptions": {
      "strictMetadataEmit": true
   }
}

I was not able to find a documentation for the angularCompilerOptions on the Internet...

The npm package in node_modules is:


I found the button-template by searching for CSS-Classes in button.component.ngfactory.js but the exported ButtonComponentNgFactory seems to be imported nowhere.


回答1:


I could not get this to work, but another approach did work very well - it packed the template into different formats of JS and does all the work: https://medium.com/@nikolasleblanc/building-an-angular-4-component-library-with-the-angular-cli-and-ng-packagr-53b2ade0701e



来源:https://stackoverflow.com/questions/47655081/exporting-ui-components-in-angular-5-template-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!