Babel plugin to resolve components based on their dirname when an index file is not present
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.babelrc
.eslintignore chore(npm): bump dependencies Jun 21, 2018
.eslintrc chore(npm): upgrade dev stack Jul 29, 2017
.gitignore
.npmignore feat(update): minor changes Dec 6, 2018
.travis.yml
LICENSE
README.md
package.json

README.md

Babel Component Resolver Plugin

npm version license build status dependencies status devDependencies status Codacy Badge Codacy Badge npm downloads

Babel plugin to resolve components based on their dirname when an index file is not present.

Let you drop index.js files when you only want to export a single file for a component.

Useful for React with CSS modules, where you end up with one folder per component (.js & .css).

Also enables extra root folders (think NODE_PATH) to look for exotic resolves.

Usage

When you require a folder:

import BarComponent from './BarComponent';

You usually have to use an index.js file as an export proxy:

├── BarComponent
│   ├── BarComponent.js
│   └── index.js

With this plugin, you can clean up the structure and have working directory imports:

├── BarComponent
│   └── BarComponent.js

Quickstart

npm i --save-dev babel-plugin-component-resolver
  1. Add the plugin to your .babelrc

    {
      "plugins": [
        "transform-object-rest-spread", "component-resolver"]
      ]
    }
  2. The root option allows you to specify additional root folders to resolve files.

    {
      "plugins": [
        "transform-object-rest-spread",
        ["component-resolver", {
          "root": ["./src"]
        }]
      ]
    }
  3. By default, the NODE_PATH env var will be processed to look for exotic resolves.

Available scripts

Script Description
start Alias of test:watch
test Run mocha unit tests
test:watch Run and watch mocha unit tests
lint Run eslint static tests
compile Compile the library
compile:watch Compile and watch the library

Authors

Olivier Louvignes

Implementation inspired by babel-plugin-module-resolver by @tleunen

License

The MIT License

Copyright (c) 2016 Olivier Louvignes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.