Webstorm how to choose shortest import

Hello,
I have a question about is there a way WebStorm to choose the shortest import ?
So what I mean, for example if we have such file structure.


Now the root components folder under the src is with alias '@components'.

When I want to import the DefaultArticleHeader in the DefaultArticleHeader.test.tsx file
the auto import with alias will look like that.

import DefaultArticleHeader from "@components/CMS/components/DefaultArticleHeader"

while it can just be

import DefaultArticleHeader from "./DefaultArticleHeader"


The problem is non of the members from my team use WebStorm, and some of them are writing the imports by hand, and they find the long import harder to read, and they use the aliases only when they need to avoid imports like import Something from "../../../../components/....."

0
4 comments

Please try setting Use path mappings from tsconfig.json to Only in files outside specified paths in Settings | Editor | Code Style | TypeScript - does it make things any better?

1

Yes, that is working great.
Thanks.

0

Elena Pogorelova do you know of any similar options for javascript? In my current project we didnt move to ts yet, and webstorm always makes auto-imports in JS files starting from '@' alias . 

0

It's Use path aliases : Only in files outside specified paths in Settings | Editor | Code Style | JavaScript 

0

Please sign in to leave a comment.