EmberJS; How to import files using the root path?

I have this model along this path:

 /my-project/app/models/my-model.js 

And I want to import it from route along this path:

 /my-project/app/routes/battles/battle/combats/new.js 

The import proposal is as follows:

 import MyModel from '../../../../models/my-model'; 

The way is crazy, I have to use a system of attempts and errors to find out. Also, if I want to import the same model into another component, I can’t just copy and paste, because this path is only valid for a specific path. For the same reason, if I change the path to the component importing my model, I need to update the import path.

I would like to have a path relative to the project root, for example:

 import MyModel from '/models/my-model'; 

Is it possible?

+5
source share
1 answer

Ember CLI registers everything in app/ under the project name, so the import should look like this:

 import MyModel from 'my-project/models/my-model'; 
+11
source

Source: https://habr.com/ru/post/1238837/


All Articles