Import relative to package.json or local module name in WebStorm

Hello,

 

I'm trying to import a local component, but in the import I want to use it:

import Icon from 'AppName/styles/Icons';

instead of:

import Icon from '../../styles/Icons';

or instead of

import Icon from 'styles/Icons';

how can I do this, I've searched a lot, but didn't find something useful.

2 comments

Is AppName your project name? then no, this can't be done... there is no way to set a prefix for the root path - aliases can only be set for subfolders (using webpack config, or via a workaround from https://youtrack.jetbrains.com/issue/WEB-22717#focus=streamItem-27-1558931-0-0)

 

Generating paths relative to project root is possible with Use paths relative to the project, resource or sources roots option (Settings | Editor | Code Style | JavaScript | Imports)

0

Yes AppName is the name that is on my package.json

0

Please sign in to leave a comment.