Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Notes

  • By default, the function sets the basedir browserify option to the current working directory. To specify an alternative directory for resolving relative require paths, set basedir option.
  • By default, the function sets the paths browserify option to include the current working directory and the paths extracted from the NODE_PATH environment variable. To specify alternative directories for resolving non-relative require paths, set the paths option to specify an array of directories for browserify to search.

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.
         --path path           Directory paths in which to search for modules
                               referenced using non-relative paths. To specify
                               multiple directories, set a --path flag for each
                               directory to search.
         --basedir path        Directory from which to resolve relative paths.
                               Default: current working directory.

Examples

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