I am seeking a deeper understanding of the ES6 import function and could use some assistance.
The Situation
Imagine that I have a portion of code in my application that is frequently used, so I organize all of it into a folder for convenience.
Now, in three separate files, I have something like this (keep in mind, I am using TypeScript, so the file extensions end in '.ts'):
file0.ts:
import {AbstractCoreCommunicationClass} from '../../../core-packages/communication/abstract-core-communication'
file1.ts:
import {AbstractCoreCommunicationClass} from '../communication/abstract-core-communication'
file2.ts:
import {AbstractCoreCommunicationClass} from '../../../../../core-packages/communication/abstract-core-communication'
My Goal
I hope to simplify these references to something like this:
file0.ts:
import {AbstractCoreCommunicationClass} from '@my-communication-core/abstract-core-communication'
file1.ts:
import {AbstractCoreCommunicationClass} from '@my-communication-core/abstract-core-communication'
file2.ts:
import {AbstractCoreCommunicationClass} from '@my-communication-core/abstract-core-communication'
Methods I've Attempted
I am aware that in Laravel (another framework), modules can be created and loaded by modifying core loader definition files such as composer.json or the main config/app.php file.
I have searched for a similar approach in the package.json file to reference non-npm packages, but haven't had any luck. The closest information I found was about NPM private packages, which would achieve the same goal if I'm willing to pay $7/month forever to host my package on their servers.
There must be a way to manage local package dependencies like this, but so far I haven't come across it, and that's why I need YOUR input!
All contributions are welcome. Every idea counts, even if it seems off track. Share your thoughts so we can work together to find a solution that benefits everyone!