Create a bundle from a string using browserify.
var bundle = require( '@stdlib/_tools/browserify/string' );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
windowglobal. - 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
arrayof browserify transform modules and functions (including corresponding options) to be applied during bundling. - plugins: an
arrayof browserify plugins (including corresponding options) to be applied during bundling. - external: an
arrayof modules to omit when generating a bundle. Omitted modules are assumed to be present in a separate external bundle.
- By default, the function sets the
basedirbrowserify option to the current working directory. To specify an alternative directory for resolving relative require paths, setbasediroption. - By default, the function sets the
pathsbrowserify option to include the current working directory and the paths extracted from theNODE_PATHenvironment variable. To specify alternative directories for resolving non-relative require paths, set thepathsoption to specify anarrayof directories for browserify to search.
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() );
}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.
$ browserify-string --export-name beep 'module.exports = require( "path" ).join;'