1
votes

In the default app/app.js generated by ember cli v2.3.0 these import statements are at the top:

import Ember from 'ember';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

Usually './' would mean current directory. And specified in app/app.js current directory would be the app directory.

What confuses me is that both ./resolver and ./config/environment work. There is a app/resolver.js, but there is no app/config/environment.js. Instead config/environment.js sits at the root directory of the ember project.

So what's the deal with './'? How is it working in both cases?

2

2 Answers

0
votes

This has to do with the ember-cli loader. I'll be honest, I'm far from a module loading expert, but if you step through this in a live app you'll see that findModule(name, referrer), name = "my-app/config/environment", referrer = "my-app/app", scoping to the module "my-app".

So the ./ is more of a reference to the Module, here "my-app", and not just a directory.

0
votes

You said that:

Usually './' would mean current directory.

That is totally true. ./ means current directory and ../ means one level up.

The confusing part is the app directory, which is omited while building the ember application.

./resolver works because they are in the same directory.

./config/environment works because they will be in the same directory after omiting the app directory. By the way, my-app/config/environment works because app directory will be ignored all of it's first level directories will be placed in the root.