browserify-requireify

Require any type of file when using browserify

Usage no npm install needed!

<script type="module">
  import browserifyRequireify from 'https://cdn.skypack.dev/browserify-requireify';
</script>

README

requireify

Build Status

A browserify transform for require()-ing non-JS files. Should work with browserify >= 5.x.x.

It accomplishes this by wrapping the contents of the file in a module.exports = '<contents>' block.

Installation

Install via NPM: npm install browserify-requireify

requireify is already taken :(

Usage

var browserify = require('browserify'),
    requireify = require('browserify-requireify');

var b = browserify([ 'my/files/and/stuff.js' ]);
b.transform(requireify({
    extensions: [ 'txt', 'html', 'css' ]
}));

b.bundle(function(err, buffer) {
    console.log(buffer.toString());
});

Options

extensions: An array of (case-insensitive) file extensions. requireify won't do anything if the file doesn't have an extension contained in this array.

Development

Run tests with npm test