简体   繁体   English

使用aot导入库的单个lodash函数

[英]Import single lodash functions for libraries with aot

I'm trying to use lodash with the syntax "import * as includes from 'lodash.includes';" 我正在尝试使用lodash语法“import * as includes from'lodash.includes';” so i don't need to install all lodash library and just the functions that I need. 所以我不需要安装所有lodash库,只需要安装我需要的功能。 Everything works fine but aot. 一切都很好但是很好。 I build my library to use it in other project as a node_modules and when I do ng serve everything works fine but when doing ng serve --aot I got: "Module not found: Error: Can't resolve 'lodash.includes' in etc...". 我构建我的库以在其他项目中使用它作为node_modules并且当我做服务时一切正常但在做服务时 - 我得到了:“找不到模块:错误:无法解析'lodash.includes'in等等...”。 I could solve the problem by installing lodash in my library project and use it with the syntax "import * as _ from 'lodash';" 我可以通过在我的库项目中安装lodash来解决问题,并使用语法“import * as _ from'lodash';” but I'd like to have only the dependencies that I need not the whole lodash library. 但我想只有我不需要整个lodash库的依赖项。 Any guess? 有什么猜测?

If you don't want to include the entire Lodash library in your Angular project, then you need to use the lodash-es library as a dependency instead of the normal lodash library as a dependency. 如果您不想在Angular项目中包含整个Lodash库,那么您需要使用lodash-es库作为依赖项而不是普通的lodash库作为依赖项。 Just change it in your package.json file and then in each of your references within your project to point to that library instead. 只需在package.json文件中更改它,然后在项目中的每个引用中更改它以指向该库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM