babel-plugin-directory-resolver

1.2.0 • Public • Published

Babel Directory Resolver Plugin

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

This plugin adds an extra resolution for directories, as it will look for ${dirname}.js and thus allows you to drop index.js files inside your directories.

Useful for frontend components when you have a directory per component, with either styles, or tests along the component file.

Usage

When you require a folder:

import BarComponent from './BarComponent';

You must use an index.js file as an export proxy:

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

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

├── BarComponent
│   ├── BarComponent.js
│   └── BarComponent.spec.js

Quickstart

yarn add --dev directory-resolver
  1. Add the plugin to your .babel.config.js (or .babelrc)
module.exports = {
  presets: [['@babel/preset-env']],
  plugins: ['directory-resolver']
};

Available scripts

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

Authors

Olivier Louvignes

License

The MIT License

Copyright (c) 2019 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.

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-directory-resolver

Weekly Downloads

16

Version

1.2.0

License

MIT

Unpacked Size

19.4 kB

Total Files

7

Last publish

Collaborators

  • mgcrea