简体   繁体   中英

IntelliJ and AngularCLI 6 - import library by package name

I have an Angular CLI 6 project, with contains 2 components:

  • a library with services/components
  • a project which uses this library

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:

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 ).

Thank you.

You can try adding one more path mapping to your tsconfig.json :

"paths": {
      "some-lib": [
        "dist/some-lib",
        "projects/some-lib/src/lib/some-lib.module"
      ],
      "some-lib/*": [
        "dist/some-lib/*"
      ]
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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