vihanb / babel-plugin-wildcard

Wildcard imports import a directories JS files
MIT License
186 stars 27 forks source link

Additional features #9

Open serhiipalash opened 7 years ago

serhiipalash commented 7 years ago

Hello! Very nice plugin! Can you add more functionality to it?

1) Possibility to import nested folder's index.js by folder name. I have such a project structure

/components
   /Button
      index.js
      style.css
   /Header
      index.js
      style.css

Is it possible to import components like this?

import { Button, Header } from './components/*'

2) Possibility to import nested folder's directory named file by folder name like Webpack DirectoryNamedWebpackPlugin does There is an implementation of it for Babel, but it is not supported any more. https://github.com/mdluo/babel-plugin-directory-named-module/issues/1

It would be great to get rid of index.js all over my React Native project. Thanks in advance for your help!

RayBenefield commented 6 years ago

I've actually started working on the first one, the nested folder structure system, this morning. :) It will be my first public open source pull request. I've got the initial use case setup, but I'm working on making sure it is fully recursive so I'm working on the importing multiple files deeply now and I still need to figure out the best way to handle index.js (I may save this for another go Pull Request later). This is also my first time working on a babel plugin.

https://github.com/RayBenefield/babel-plugin-wildcard/tree/Recursive-Imports

Still working on it and hopefully I'll get it done in the next day or two as I need it for a project I'm working on too.

As for the second one, that looks interesting, for me that feels out of scope for this plugin as it isn't really a "wildcard" thing.

serhiipalash commented 6 years ago

I've actually started working on the first one

Great! Good luck!

RayBenefield commented 6 years ago

I've put in the initial pull request for the first portion (#11). However it doesn't solve your use case @serhiipalash . It doesn't specially handle index.js and I haven't quite figured out filtering yet. Right now it just handles:

|- index.js
|- dir
    |- a.js
    |- c.js
    |- nested
        |- b.js

the allowing JS:

import * as Items from './dir';
console.log(Items.Nested.B());