Template tags for base directory path importing.
If you are using import
syntax, consider something like babel-plugin-module-alias
Template tags for base directory path importing.
If you are using import
syntax, consider something like babel-plugin-module-alias
// Use a tag to make module imports work better from project base! | |
// This should be in a top level file. | |
global.base = (literals) => `${__dirname}/${literals}`; | |
// Now in any other file, potentially several directory levels deep we can use tags. | |
const Student = require(base`modules/path/to/student`); | |
console.log(new Student()); |
// modules/path/to/student.js | |
const Person = require(base`modules/path/to/person`); | |
module.exports = class Student extends Person { }; |