https://github.com/d-oliveros/es6-requireindex
Helper to require() directories with es6 support.
https://github.com/d-oliveros/es6-requireindex
Last synced: about 2 months ago
JSON representation
Helper to require() directories with es6 support.
- Host: GitHub
- URL: https://github.com/d-oliveros/es6-requireindex
- Owner: d-oliveros
- License: mit
- Created: 2015-12-14T05:07:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-23T06:16:47.000Z (almost 9 years ago)
- Last Synced: 2025-03-06T02:03:48.839Z (2 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# es6-requireindex
Requires the modules in a directory, with support for es6-style exports (aka `export default`), and the browser via webpack.If a module exports a default object, requireIndex will expose the default object as the module's export (instead of exposing an object with the `default` property referencing the es6 default export).
### Usage
```js
// Short form. eg. in index.js
module.exports = require('es6-requireindex')();
``````js
// With options
var requireIndex = require('es6-requireindex');
var targetDir = path.join(__dirname, 'somedir');module.exports = requireIndex(somedir, {
recursive: true|false, // Default: true
requireES6Defaults: true|false // Default: true
});
```If you want to use it with webpack to require a folder, you must do:
```js
var ctx = require.context(__dirname, true, /^(.*\.((js|jsx)$))[^.]*$/igm);
module.exports = requireIndex(ctx, [opts]);
```To require all the files in a folder in an isomorphic fashion (eg with browser and server support), you can do:
```js
var ctx;try {
ctx = require.context(__dirname, true, /^(.*\.((js|jsx)$))[^.]*$/igm);
} catch (err) {}module.exports = requireIndex(ctx);
```### Options
- recursive (Default: true)If 'true', will require recursively through folders.
- requireES6Defaults (Default: true)
if 'true', will require the 'default' property of the required module, and when 'false', will require the whole exported object. This is helpful for es6 modules, where you can export a default object, because a es5-styled require will get the whole module, which has the default export in a property called 'default'.
### Tests
```
npm test
```Cheers.