Skip to content

Commit f9fcd6d

Browse files
committed
Add support for generating a standalone bundle
1 parent bace3d2 commit f9fcd6d

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/node_modules/@stdlib/_tools/browserify/string/bin/cli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ function main() {
6262

6363
// Extract options...
6464
opts = {};
65+
if ( flags.standalone ) {
66+
opts.standalone = flags.standalone;
67+
}
6568
if ( flags[ 'export-name' ] ) {
6669
opts.exportName = flags[ 'export-name' ];
6770
}

lib/node_modules/@stdlib/_tools/browserify/string/bin/opts.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"export-name",
44
"transform",
55
"plugin",
6-
"external"
6+
"external",
7+
"standalone"
78
],
89
"boolean": [
910
"help",

lib/node_modules/@stdlib/_tools/browserify/string/bin/usage.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Options:
55

66
-h, --help Print this message.
77
-V, --version Print the package version.
8+
--standalone name Generate a UMD bundle with the supplied export
9+
name. The generated bundle will work with other
10+
module systems. If no module system is found, the
11+
export name is attached to the `window` global.
812
--export-name name Bundle export target. The target is the name used
913
to load the bundle from the external environment.
1014
In contrast to a standalone UMD bundle, a require

lib/node_modules/@stdlib/_tools/browserify/string/lib/bundle.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var TMPFILE = join( tmpdir(), '.__browserify-string-tmp-file_' );
3030
* @param {string} str - input string
3131
* @param {string} [dest] - output file path
3232
* @param {Options} [options] - browserify options
33+
* @param {string} [options.standalone] - standalone browserify bundle export name
3334
* @param {string} [options.exportName] - bundle target name
3435
* @param {Array} [options.transforms] - transforms to apply when bundling
3536
* @param {Array} [options.plugins] - plugins to apply when bundling
@@ -87,6 +88,9 @@ function bundle( str, dest, options, clbk ) {
8788
opts = dest;
8889
cb = options;
8990
}
91+
if ( hasOwnProp( opts, 'standalone' ) && !isString( opts.standalone ) ) {
92+
throw new TypeError( 'invalid option. `standalone` option must be a string. Option: `'+opts.standalone+'`.' );
93+
}
9094
if ( hasOwnProp( opts, 'exportName' ) && !isString( opts.exportName ) ) {
9195
throw new TypeError( 'invalid option. `exportName` option must be a string. Option: `'+opts.exportName+'`.' );
9296
}
@@ -122,7 +126,9 @@ function bundle( str, dest, options, clbk ) {
122126
debug( 'Encountered an error when creating a temporary file: %s', error.message );
123127
return done( error );
124128
}
125-
if ( opts.exportName ) {
129+
if ( opts.standalone ) {
130+
b = browserify( tmpfile, opts );
131+
} else if ( opts.exportName ) {
126132
b = browserify( opts );
127133
b.require( tmpfile, {
128134
'expose': opts.exportName

0 commit comments

Comments
 (0)