Bundle

Create a bundle from a string using browserify.

Usage

var bundle = require( '@stdlib/_tools/browserify/string' );

bundle( str, [dest,] [options,] clbk )

Generates a bundle from a string using browserify.

var str = 'module.exports = require( "url" );';

bundle( str, clbk );

function clbk( error, bundle ) {
    if ( error ) {
        throw error;
    }
    console.log( bundle.toString() );
}

To specify an output file path, provide a dest argument.

var str = 'module.exports = require( "url" );';

bundle( str, './bundle.js', clbk );

function clbk( error ) {
    if ( error ) {
        throw error;
    }
}

The function accepts any browserify option, as well as the following options:

  • standalone: standalone browserify export name. Setting this option instructs the function to generate a UMD bundle with the supplied export name. The generated bundle will work with other module systems. If no module system is found, the export name is attached to the window global.
  • exportName: bundle export target. The target is the name used to load the bundle from the external environment. In contrast to a standalone UMD bundle, a require function is exposed as a global variable.
  • requireName: name of function exposed to support external loading of modules from a browserify bundle.
  • transforms: an array of browserify transform modules and functions (including corresponding options) to be applied during bundling.
  • plugins: an array of browserify plugins (including corresponding options) to be applied during bundling.
  • external: an array of modules to omit when generating a bundle. Omitted modules are assumed to be present in a separate external bundle.

Examples

var bundle = require( '@stdlib/_tools/browserify/string' );

var str = 'module.exports = require( "path" ).join;';

var opts = {
    'exportName': 'beep'
};

bundle( str, opts, clbk );

function clbk( error, bundle ) {
    if ( error ) {
        throw error;
    }
    console.log( bundle.toString() );
}

CLI

Usage

Usage: browserify-string [options] [<string>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --standalone name     Generate a UMD bundle with the supplied export
                               name. The generated bundle will work with other
                               module systems. If no module system is found, the
                               export name is attached to the `window` global.
         --export-name name    Bundle export target. The target is the name used
                               to load the bundle from the external environment.
                               In contrast to a standalone UMD bundle, a require
                               function is exposed as a global variable.
         --require-name name   External `require` name to support requiring
                               packages within a browserify bundle from the
                               external environment.
  -t,    --transform module    Apply a transform when bundling. To apply
                               multiple transforms, set a --transform flag
                               for each transform.
  -p,    --plugin module       Register a plugin. To register multiple plugins,
                               set a --plugin flag for each plugin.
  -u,    --external module     Omit a module from an output bundle. Omitted
                               modules are assumed to be present in a separate
                               external bundle. To omit multiple modules, set an
                               --external flag for each module to omit.

Examples

$ browserify-string --export-name beep 'module.exports = require( "path" ).join;'