为具有aot的库导入单个lodash函数 [英] Import single lodash functions for libraries with aot

查看:100
本文介绍了为具有aot的库导入单个lodash函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用lodash,语法为"import * as from'lodash.includes';".因此,我不需要安装所有lodash库以及仅需要的功能.一切正常,但是可以.我建立了自己的库以在其他项目中将其用作node_modules,当我执行ng服务时一切正常,但是当执行ng服务--aot时,我得到了:未找到模块:错误:无法解析'lodash.includes'等等...". 我可以通过在我的库项目中安装lodash并将其与语法"import * as _ from'lodash';一起使用"来解决该问题.但是我只想拥有不需要整个lodash库的依赖项. 有任何猜想吗?

I'm trying to use lodash with the syntax "import * as includes from 'lodash.includes';" so i don't need to install all lodash library and just the functions that I need. 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...". I could solve the problem by installing lodash in my library project and use it with the syntax "import * as _ from 'lodash';" but I'd like to have only the dependencies that I need not the whole lodash library. Any guess?

推荐答案

如果您不想在Angular项目中包含整个Lodash库,则需要使用

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. Just change it in your package.json file and then in each of your references within your project to point to that library instead.

这篇关于为具有aot的库导入单个lodash函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆