1.0.0 • Published 7 years ago

contents-loader v1.0.0

Weekly downloads
45
License
MIT
Repository
github
Last release
7 years ago

contents-loader Build Status

Webpack loader to import the contents of a directory.

For a directory structure like:

└── abc
    ├── foo.js
    ├── bar.js
    ├── baz.js
    ├── somethingElse.txt
    └── styles.css

contents-loader!./abc/ generates code like:

import * as _0 from "./abc/foo.js";
import * as _1 from "./abc/bar.js";
import * as _2 from "./abc/baz.js";
export default { "foo.js": _0, "bar.js": _1, "baz.js": _2 };

If you're using vanilla Webpack, this loader has little advantage over the built-in require.context('./abc', false, /\.js$/). If, however, you're using webpack-rollup-loader or similar, require.context will only be processed by Webpack, resulting in suboptimal code generation.

Installation

npm install --save-dev contents-loader

Usage

// trailing slash is important
import modules from 'contents-loader!./path/to/directory/';

// use the `match` option to specify which files to import
// (defaults to `/\.js$/i`)
import images from 'contents-loader?match=\\.png$!./path/to/images/';
1.0.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago