Skip to content

Commit

Permalink
Support for dynamic standalone module name.
Browse files Browse the repository at this point in the history
If opts.standalone === true, then the standalone name will be set to the filename (without extension) of the source file.
Addresses issue browserify#42.
  • Loading branch information
sethmcl committed Aug 15, 2014
1 parent 718fb97 commit 8aa9f3b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,24 @@ module.exports = function (opts) {

return stream;

function getStandaloneName (filename) {
var standalone = opts.standalone;

if (standalone === true && filename) {
standalone = getDynamicStandaloneName(filename);
}

return standalone.toString();
}

function getDynamicStandaloneName (filename) {
return path.basename(filename).split('.')[0];
}

function write (row, enc, next) {
if (first && opts.standalone) {
var pre = umd.prelude(opts.standalone).trim();
var standalone = getStandaloneName(row.file);
var pre = umd.prelude(standalone).trim();
stream.push(Buffer(pre + 'return '));
}
else if (first && stream.hasExports) {
Expand Down Expand Up @@ -96,9 +111,10 @@ module.exports = function (opts) {
stream.push(Buffer('},{},' + JSON.stringify(entries) + ')'));

if (opts.standalone) {
var standalone = getStandaloneName();
stream.push(Buffer(
'(' + JSON.stringify(stream.standaloneModule) + ')'
+ umd.postlude(opts.standalone)
+ umd.postlude(standalone)
));
}

Expand Down

0 comments on commit 8aa9f3b

Please sign in to comment.