[英]IntelliJ and AngularCLI 6 - import library by package name
I have an Angular CLI 6 project, with contains 2 components: 我有一个Angular CLI 6项目,包含2个组件:
When I want to use the library in the frontend project, I should use for example: 当我想在前端项目中使用库时,我应该使用例如:
import { SomeLibModule } from "some-lib";
Instead, with IntelliJ, when I'm using auto-import feature (ie I'm typing SomeLibModule
and I'm hitting Alt + Enter), the specified import is: 相反,使用IntelliJ,当我使用自动导入功能时(即我正在键入
SomeLibModule
并且我正在按Alt + Enter键),指定的导入是:
import {SomeLibModule} from '../../projects/some-lib/src/lib/some-lib.module';
How can I change this behavior to prefer imports using their package name? 如何更改此行为以使用其包名更喜欢导入?
Here a simple repository to reproduce this behavior : https://github.com/lbar/ngcli-with-lib (the library import is in app.module.ts
). 这里有一个简单的存储库来重现这种行为: https : //github.com/lbar/ngcli-with-lib (库导入在
app.module.ts
)。
Thank you. 谢谢。
You can try adding one more path mapping to your tsconfig.json
: 您可以尝试向
tsconfig.json
添加一个路径映射:
"paths": {
"some-lib": [
"dist/some-lib",
"projects/some-lib/src/lib/some-lib.module"
],
"some-lib/*": [
"dist/some-lib/*"
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.