JSPM

babel-plugin-require-root-rewrite

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 34
  • Score
    100M100P100Q99020F
  • License MIT

A Babel plugin for requiring files relative to the project root.

Package Exports

  • babel-plugin-require-root-rewrite

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 (babel-plugin-require-root-rewrite) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

babel-plugin-require-root-rewrite

A Babel plugin for requiring files relative to the project root.

Example

In: /path/to/project/containers/Register/Register.js

const BaseAuthForm = require('~/components/BaseAuthForm');

or

import BaseAuthForm from '~/components/BaseAuthForm';

Out

var BaseAuthForm = require('../../components/BaseAuthForm');

Installation

$ npm install babel-plugin-require-root-rewrite

Usage

.babelrc

{
  "plugins": [
    ["babel-plugin-require-root-rewrite", {
      "pattern": "^~/",
      "basePath": "lib",
      "overrides": [
        "api",
        "server"
      ]
    }]
  ]
}

Via CLI

$ babel --plugins babel-plugin-require-root-rewrite script.js

Via Node API

require('babel-core').transform('code', {
  plugins: ['babel-plugin-require-root-rewrite']
});