I'm fairly new to Aurelia so please be gentle with me if this is an obvious question or even something one should not consider doing. From reading the documentation and various resources on the web this does not seem to be addressed anywhere.
As my project increased in size I restructured folders and files. While refactoring it felt a bit cumbersome, as to check the correct depth of the path, and also when I moved view models I needed to change the import path as well.
Currently I need to import certain files in my view models as:
import {log} from './../../services/log';
What I would find more comfortable would be to have a relative path starting from the root of the project like:
import {log} from 'services/log';
Is there anything I'm missing or simply not understanding? I know that with the ./ the relative path from the current file is specified.
Update:
I tried the same with the Aurelia Contact Manager Tutorial where all files in the src folder are on the same level. If I move the 'wep-api.ts' file into a 'src/services' folder and want to import that file from a viewmodel inside 'src/components/users' I need to use the import as
import {WebAPI} from './../../services/web-api';
It does not seem to work with only 'services/web-api' and the error is
[ts] cannot find module 'services/web-api'
The aurelia.json file includes
"paths": {
"root": "src", ...
As it appears the typescript compiler needs to be configured to access the desired path.
tsconfig.json
{
...
"compilerOptions": {
...
"baseUrl": ".",
"paths": {
"*":["src/*"]
}
}
...
}
With this in place, imports now work as e.g. 'services/web-api' (located in 'src') from any file and folder structure below 'src'.
Kudos go to stoffeastrom from the Aurelia gitter channel who actually pointed out the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With