npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

babel-plugin-package-name-import

1.0.3 • Public • Published

babel-plugin-package-name-import

Build Status

Import files from the current package by name

Installing

Install it locally to your project by running:

yarn add --dev babel-plugin-package-name-import

Add the plugin to your Babel configuration:

{
  "plugins": ["package-name-import"]
}

Usage

Given that your package.json contains:

{
  "name": "project",
  "main": "src/index.js"
}

You can import files from the current project by name:

import project from 'project'

Note that require is not supported as its argument can be dynamically computed.

eslint-plugin-import

If your project uses eslint-plugin-import, ensure that it can resolve current project imports by including the eslint-import-resolver-package-name-import plugin.

Flow

If your project uses Flow, ensure that it can resolve current project imports by adding to .flowconfig:

[options]
module.name_mapper='^project$' -> '<PROJECT_ROOT>'
module.name_mapper='^project\/\(.*\)$' -> '<PROJECT_ROOT>/\1'

Note that <PROJECT_ROOT> is a special token and should be left unmodified.

install

npm i babel-plugin-package-name-import

Downloadsweekly downloads

271

version

1.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability