8
votes

I find the import path in ES6 modules very confusing when using it in Ember CLI. For example, if I want to import a model deep in my application, I end up doing something like this:

import User from '../../../../../models/user';

This is an exercise of trial and error, as it's hard to easily visualize how deep in the folder tree I'm using this from. Even worse, if I refactor my files, everything breaks.

So alternatively, I can use an absolute path like this:

import User from 'app-name/models/user';

I prefer not to hard-code the app name into the path, because it can change.

Is there a shorthand to specify the app root?

./ doesn't work because ./ implies current path.

import User from './models/user';
1
This post has a variety of ideas: lostechies.com/derickbailey/2014/02/20/…Andrew Odri

1 Answers

2
votes

Unfortunately there is no way to programmatically name ES6 imports at least in Ember so you can't use ENV.modulePrefix.

However there is a workaround. Whenever you want to change module prefix run this GNU sed command from ZSH inside Ember root.

sed -i 's/previousName/newName/g' **/*