ng build不包含库模块的组件类代码 [英] ng build does not include component class code of library modules
问题描述
我创建了一个库,其中包含其中包含组件的模块.
I have created a library that has modules that have components in them.
我的图书馆public_api.ts具有此功能:
My library public_api.ts has this:
export * from './src/app/modules/my-mod-1/my-mod-1.module';
现在,此模块具有可在module.ts文件中导出并声明的组件
Now this module has components that are exported and declared in the module.ts file
@NgModule({
imports: [
...
],
declarations: [
MyOneComponent
],
exports: [
MyOneComponent
]
})
现在,我使用ng-packagr创建软件包,并使用.tgz文件中的npm install将其导入另一个项目中.
Now I create the package using ng-packagr and import it in another project using npm install from the .tgz file.
当我在开发模式下运行该组件时,该组件可以与所有生命周期挂钩正常工作.
The component works fine with all lifecycle hooks when I run it in development mode.
但是当我使用ng build
创建构建时,它不会调用生命周期挂钩.尽管它确实在组件的html文件中打印了所有内容,但是似乎缺少了组件类代码.
But when I create a build using ng build
, it does not call the lifecycle hooks. Although it does print everything in the html file of the component, but the component class code seems to be missing.
在运行开发模式时,我签入了vendor.js
文件,在那里我可以轻松地找到组件类代码(实际上,我搜索了打印在组件类代码中的console.log代码,它在那里显示)
I checked in vendor.js
file when running the development mode, and there I can easily find the component class code (actually I searched for a console.log code that I printed in the component class code and it was showing up there)
但是由build命令生成的main.xxxxxx.js中缺少相同的代码.而且build命令根本不会创建vendor.js文件,因为main.js中包含了vendor.js
But same code is missing from main.xxxxxx.js that is built by the build command. And the build command does not create a vendor.js file at all because vendor.js is included in main.js
所以问题是项目构建中未包含库类代码,为什么会发生这种情况?
项目中有太多代码,我想不起来应该在此处粘贴代码的哪些部分来帮助您理解问题.所以请让我知道我还要在这里复制什么.
There is so much code in the projects that I cannot think of what parts of code should I paste here to help you understand the issue. So please do let me know what else I should copy here.
谢谢
推荐答案
我从这里获得了一些帮助: https://github.com/angular/angular-cli/issues/11394
I got some help from here: https://github.com/angular/angular-cli/issues/11394
似乎:
1)您应该将库使用的所有组件和模块导出到public_api.ts
文件中.
1) you should export all components and modules used by the library in the public_api.ts
file.
2)显然删除了node_modules
文件夹,然后通过npm install
重新安装它似乎可行,看来库中的缓存文件已损坏
2) apparently deleting the node_modules
folder and then re-installing it by npm install
seems to work, it appears that the library cached files were corrupt
现在我的应用程序也可以在生产环境中使用!
Now my app works in production as well!
这篇关于ng build不包含库模块的组件类代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!