All Projects → vihanb → Babel Plugin Wildcard

vihanb / Babel Plugin Wildcard

Licence: mit
Wildcard imports import a directories JS files

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Babel Plugin Wildcard

Generator Babel Plugin
Babel Plugin generator for Yeoman
Stars: ✭ 88 (-48.24%)
Mutual labels:  babel-plugin
Babel Plugin Mobx Deep Action
Reduces `action` and `runInAction` boilerplates
Stars: ✭ 110 (-35.29%)
Mutual labels:  babel-plugin
Babel Plugin Transform Incremental Dom
Turn JSX into IncrementalDOM
Stars: ✭ 146 (-14.12%)
Mutual labels:  babel-plugin
Jsx Control Statements
Neater If and For for React JSX
Stars: ✭ 1,305 (+667.65%)
Mutual labels:  babel-plugin
Babel Plugin Recharts
Stars: ✭ 108 (-36.47%)
Mutual labels:  babel-plugin
Babel Plugin Runtyper
⚡️ Runtime type-checker for JavaScript
Stars: ✭ 117 (-31.18%)
Mutual labels:  babel-plugin
Modify Babel Preset
💫 Create a modified babel preset based on an an existing preset.
Stars: ✭ 85 (-50%)
Mutual labels:  babel-plugin
Babel Plugin Graphql Tag
Compiles GraphQL tagged template strings using graphql-tag.
Stars: ✭ 156 (-8.24%)
Mutual labels:  babel-plugin
Js Proposal Algebraic Effects
📐Let there be algebraic effects in JS
Stars: ✭ 110 (-35.29%)
Mutual labels:  babel-plugin
Extract React Types
One stop shop to document your react components.
Stars: ✭ 141 (-17.06%)
Mutual labels:  babel-plugin
Babel Plugin React Persist
Automatically useCallback() & useMemo(); memoize inline functions
Stars: ✭ 91 (-46.47%)
Mutual labels:  babel-plugin
Babel Plugin Jsx Adopt
Stars: ✭ 94 (-44.71%)
Mutual labels:  babel-plugin
Babel Plugin Polished
Compile polished helper functions at build time
Stars: ✭ 133 (-21.76%)
Mutual labels:  babel-plugin
Idx.macro
a 'babel-macros' version of 'babel-plugin-idx'
Stars: ✭ 90 (-47.06%)
Mutual labels:  babel-plugin
Babel Plugin Object To Json Parse
This plugin converts object literal to JSON.parse
Stars: ✭ 151 (-11.18%)
Mutual labels:  babel-plugin
Babel Plugin Stateful Functional React Components
Stateful functional React components without runtime overhead
Stars: ✭ 86 (-49.41%)
Mutual labels:  babel-plugin
Babel Plugin Prismjs
A babel plugin to use PrismJS with standard bundlers.
Stars: ✭ 114 (-32.94%)
Mutual labels:  babel-plugin
Babel Plugin React Css Modules
Transforms styleName to className using compile time CSS module resolution.
Stars: ✭ 1,989 (+1070%)
Mutual labels:  babel-plugin
Babel Plugin React Docgen
📝 Babel plugin to add react-docgen info into your code.
Stars: ✭ 156 (-8.24%)
Mutual labels:  babel-plugin
Babel Plugin Transform Typescript Metadata
Babel plugin to emit decorator metadata like typescript compiler
Stars: ✭ 142 (-16.47%)
Mutual labels:  babel-plugin

babel-plugin-wildcard

Allows you to import all files from a directory at compile-time.

Installation

$ npm install babel-plugin-wildcard

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["wildcard"]
}

Via CLI

$ babel --plugins include script.js

Via Node API

require('babel').transform('code', {
  plugins: ['wildcard']
});

Example

With the following folder structure:

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

the following JS:

import * as Items from './dir';

will be compiled to:

const Items = {};
import _wcImport from "./dir/a";
Items.A = _wcImport;
import _wcImport1 from "./dir/b";
Items.B = _wcImport1;
import _wcImport2 from "./dir/c";
Items.C = _wcImport2;

meaning you will be able to access the items using Items.A and Items.B.


You can also selectively choose files using:

import { A, C } from "dir/*";

which in the above example would convert to:

import A from "./dir/a";
import C from "./dir/c";

The above is like doing:

import * as temp from "dir";
const { A, C } = temp;

There is also simple Glob support so given the directory structure:

|- index.js
|- dir
    |- a.js
    |- a.spec.js
    |- b.js
    |- b.spec.js

this import:

import * as tests from './dir/*.spec';

will compile to:

import aSpec from './dir/a.spec';
import bSpec from './dir/b.spec';

Files are automatically camel-cased and in the import statements the extensions are clipped unless specified otherwise (see below)

Information

  • File extensions are removed in the resulting variable. Dotfiles will be imported without their preceding . (e.g. .foo -> Foo or foo depending on settings)
  • in an import { ... } from 'foo/*', the identifiers inside { ... } are the same as what their name would be if you were to import the whole directory. This means it is the files' names' pascal/camel-cased and extensions removed etc. by default (depending on settings of course).

Options

babel-plugin-wildcard allows you to change various settings by providing an options object by using the following instead:

{
    plugins: [
        ['wildcard', { options }]
    ]
}

where { options } is the options object. The following options are available:

exts

By default, the files with the following extensions: ["js", "es6", "es", "jsx"], will be imported. You can change this using:

{
    plugins: [
        ['wildcard', {
            'exts': ["js", "es6", "es", "jsx", "javascript"]
        }]
    ]
}

If you add the extension "", it will also import subdirectories.

nostrip

By default, the file extension will be removed in the generated import statements, you can change this using:

{
    plugins: [
        ['wildcard', {
            'nostrip': true
        }]
    ]
}

This is useful when the extension of your source files is different from the outputted ones. (e.g. .jsx to .js).

useCamelCase

By default the name is converted to PascalCase, if you prefer camelCase, you may set this option to true:

{
    plugins: [
        ['wildcard', {
            'useCamelCase': true
        }]
    ]
}

noModifyCase

By default, the name will be automatically pascal cased, the following regex is used to extract the words, those words then have their first letter capitalized and are joined together:

[A-Z][a-z]+(?![a-z])|[A-Z]+(?![a-z])|([a-zA-Z\d]+(?=-))|[a-zA-Z\d]+(?=_)|[a-z]+(?=[A-Z])|[A-Za-z0-9]+

you can disable this behavior using:

{
    plugins: [
        ['wildcard', {
            'noModifyCase': true
        }]
    ]
}

Extensions are still removed (except dotfiles, see "Information").

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].