Skip to content

Instantly share code, notes, and snippets.

@jakeklassen
Last active May 4, 2016 18:46
Show Gist options
  • Save jakeklassen/1091c61ba80ce9907d6c244fa11c7e57 to your computer and use it in GitHub Desktop.
Save jakeklassen/1091c61ba80ce9907d6c244fa11c7e57 to your computer and use it in GitHub Desktop.
Template tags for base directory path importing.
// 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 { };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment