Path aliases for imports in WebStorm

前端 未结 10 1936
日久生厌
日久生厌 2020-12-02 05:31

I use webpack path aliases for ES6 module loading.

E.g. If I define an alias for utils instead of something like
import Foo from \".

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 06:18

    In PHPStorm (using 2017.2 currently), I have not been able to get webpack configs to work properly in regards to aliases.

    My fix involves using the "Directories" section of the main settings. I just had to mark each folder referenced by an alias as a sources root, then click the properties dropdown for each and specify the alias as a "Package prefix". This made everything link up for me.

    Not sure if the Directories section exists in WebStorm, but if it does, this seems to be a fool-proof method for getting import aliases working.

提交回复
热议问题