Say goodbye to
../ times million
and use absolute import paths from the app's root directory instead.
Table of contents
Example usage of the
sexy-require npm package by Sultan:
// Before, unclear what's being required 👎 const user = require('../../../database/user') // After, absolute path from the app's root dir 👍 const user = require('/database/user') // Alternatively, using an alias configured in a `.paths` file 👍 const user = require('$db/user')
so in other files
require() points to
which supports absolute paths and path aliases.
- Simple to set up: install the package and require it in your main application file.
- Supports path aliases.
- The name!
- Breaks VS Code's IntelliSense.
- Breaks path autocompletion in VS Code.
- Supports only
Example usage of the Basetag npm package by Jannik:
// Before, unclear what's being required 👎 import user from '../../../database/user' const user = require('../../../database/user') // After, $ points to the app's root dir 👍 import user from '$/database/user' const user = require('$/database/user')
Basetag creates a symlink,
or something called a junction on Windows,
node_modules/$ points to the app's root directory.
- Works with VS Code's IntelliSense.
- Path autocompletion works in VS Code.
- Supports both
- No way to configure path aliases.
- The symlink gets removed by npm when installing or removing packages,
so you need to e.g. create a
postinstallnpm script as instructed in the package's readme. Not difficult, but a little hassle.
I'm not sure which one I like more:
- Better VS Code support of Basetag.
- The name Sultan's
Just kidding –
good IDE support is more important.
Plus it also supports