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.
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
yarn add --dev directory-resolver
- Add the plugin to your
.babel.config.js
(or.babelrc
)
module.exports = {
presets: [['@babel/preset-env']],
plugins: ['directory-resolver']
};
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 |
Olivier Louvignes
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.