Package Exports
- basetag
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (basetag) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
basetag ⚾️
basetag lets you require local modules relative to your Node.js project base path
Installation · Why? · How? · License
Installation 🛠
npm i -S basetag
☝️ and that's it!
You can now use the $ basetag prefix.
No need to require basetag itself anywhere.
Why? ⚡️
What does basetag solve?
In Node.js applications we sometimes want to import local modules that are in different far away subdirectories.
This can lead to very messy looking require statements.
Using basetag you can import modules with $/ as the project base path.
If you're not convinced, check out the example below...
🤯 The modern basetag way:
const balls = require('$/baseball/balls') // ✅😓 The traditional (often messy) way:
const balls = require('../../../../baseball/balls') // ❌How? 💭
How do I use basetag?
It's really all described above and there's not much to it.
Look at the code in test/example/ for an executable example.
A larger project can have many nested subfolders as shown in the directory structure below.
Of course a real project would have more files in those subdirectories but for simplicity we'll leave those out.
Using basetag you can reference modules from the base example/ path, rather than using relative directories (i.e. ../../..).
example/
├── its/
│ └── baseballs/
│ └── all/
│ └── the/
│ └── way/
│ └── down.js
├── somewhere/
│ └── deep/
│ └── and/
│ └── random.js
└── index.jsHow does basetag work?
It's rather simple.
After installing basetag as a dependency a postinstall script creates a symlink that points from node_modules/$ to your project base path.
Everytime you use a require with $/… Node.js will look inside the $ package (i.e. our new symlink).
The lookup is routed natively to your project files.
To Node.js, both methods of requiring look the same, because the files are literally the same files. Both methods can be used in the same project and Node.js will cache imports correctly.
Compatibility
basetag supports macOS, Linux, and Windows as of version 1.1.0.