8

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';
Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
  • 1
    This post has a variety of ideas: http://lostechies.com/derickbailey/2014/02/20/how-i-work-around-the-require-problem-in-nodejs/ – Andrew Odri Mar 18 '15 at 16:51

1 Answers1

2

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' **/*
Pooyan Khosravi
  • 4,861
  • 1
  • 19
  • 20