How would I go about creating a plugin which re-maps imports when using EcmaScript 6

We use ECMAScript 6 and use imports such as

  • import logger from "Common/logger/LoggerFactory";
  • import GameLoader from "JumpyGame/model/GameLoader";
  • import httpUtils from "Core/HTTPUtils";

This confuses IntelliJ/WebStorm as Common, JumpyGame and Core does not exist in the filesystem before our build step!

We use Babel and in the build step we use moduleRoot, sourceRoot, moduleIds to for example set moduleRoot to Common with a sourceRoot of /home/user/dev/html5/common-platform-layer

IntelliJ/WebStorm know nothing of this. And if I control click on an import it can't find the destination. It seems to degrade a lot of functionality so that things like renames and refactorings does not work.

I would like to, at as low level as is suitable, replace Common with /home/user/dev/html5/common-platform-layer in imports when IntelliJ/WebStorm parses my source.

Unfortunately it's not an option to change how we name our imports as it's a company standard.

How would I go about creating the simplest plugin possible for this? It does not need to have any configuration options. Where should I start looking? It seems a bit more advanced than the most basic plugin examples I've seen. Yet, I need it so badly.

Please sign in to leave a comment.