Awesome Babel Plugin
I have been doing a lot of major re-structuring of my day job front end code this month, and I guess I’ll continue doing that at least until the end of next month. And I was looking for a better way to dealing with import paths.
As you structure grows you’ll probably have more and more of some import statements like this “import foo from ‘../../../../../bar’”. And I was thinking: there got to be a better way. And after googling for a while I found this. It is a babel plugin that let’s you use tilde to reference the root (where you webpack config lives).
If you want to import the file in the root called “bar.js” or “bar.jsx” you only have to do “import foo from ‘~/bar’” instead of having to figure out how many levels under it you are coming from.
I have used it for a few weeks now and love it. It makes it far less likely that you need to do a lot of code changes when you only are moving stuff around.