Sha256: 3af25f6fad0b0a8028a3ff2d5a8265606a938ad589a46624c575e19edaf9e134

Contents?: true

Size: 654 Bytes

Versions: 2

Compression:

Stored size: 654 Bytes

Contents

// source: http://stackoverflow.com/questions/31068698/importing-node-modules-from-root-directory-using-es6-and-babel-node

module.exports = function(babel) {
  var cwd = process.cwd();

  return new babel.Transformer("babel_relative_require", {
    ImportDeclaration: function(node, parent) {
      var ref;

      if (!babel.types.isLiteral(node.source)) { return node; }

      ref = node.source.value;

      // ensure a value, make sure it's not home relative e.g. ~/foo
      if (!ref || ref[0] !== "~" || ref[1] === "/") { return node; }

      node.source.value = cwd + "/source/" + node.source.value.slice(1);

      return node;
    }
  });
};

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
docks_theme_api-1.0.3 tasks/gulp/utilities/babel/relative_require.js
docks_theme_api-1.0.2 tasks/gulp/utilities/babel/relative_require.js