Is it possible to prefix absolute autoimports with some symbol?

Hi!

We use absolute imports (relative to project folder path) and we prefix all absolute imports with "/". Our typical import looks like:

import {WonderfulService} from '/src/services/wonderful_service.js';

This doesn't work well with Webstorm autoimport feature (at least I wasn't able to configure it correctly). When Webstorm autoimports this WonderfulService it adds the following import:

import {WonderfulService} from 'src/services/wonderful_service.js';

Like expected one but without leading slash.

It is possible to configure Webstorm to prefix all autoimports with slash?

0
2 comments

path prefixes are normally defined with path aliases (Typescript path mappings, webpack aliases, etc.). Not sure if specifying a slash as path alias works though, didn't try this

1

Thank you! Specifying a slash as alias doesn't work good (import path is prepended with 2 slashes), but I created alias "/src" that works fine!

alias: {
'/src': path.resolve(__dirname, './src/'),
},
1

Please sign in to leave a comment.