-
-
Save yoshuawuyts/57a8c459cf9b09ebe6d3cd6a3eb72976 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var path = require('path') | |
var parse = require('minimist') | |
var browserify = require('browserify') | |
var args = parse(process.argv.slice(2)) | |
var entries = args._ | |
var output = args.o || args.output | |
var main = args.m || args.main | |
var url = args.url || output | |
var options = { | |
main: main, | |
map: {}, | |
output: output, | |
url: url | |
} | |
var temp | |
var pkgPath | |
var pkg | |
entries.forEach(f=> { | |
// We need to treat the entry file differently. You can't expose an alias for it. | |
if (f === main) { | |
console.info('require:', f) | |
console.info('output:', output+'/'+'entry.js') | |
console.info('script src:', url+'/'+'entry.js\n') | |
// Going to hard code entry.js because works. | |
options.map['entry.js'] = [f] | |
} else if (f.split('/').pop() === 'index.js') { | |
pkgPath = f.split('/') | |
pkgPath.pop() | |
pkgPath = pkgPath.join('/') | |
pkg = require(path.join('../', pkgPath, 'package.json')) | |
temp = pkg.name | |
console.info('require:', f) | |
console.info('output:', output+'/'+temp+'.js') | |
console.info('expose:', temp) | |
console.info('script src:', url+'/'+temp+'\n') | |
if (temp) { | |
options.map[temp+'.js'] = [{ | |
require: f, | |
expose: temp | |
}] | |
} | |
} else { | |
temp = f.split('/').pop() | |
console.info('require:', f) | |
console.info('output:', output+'/'+temp) | |
console.info('expose:', temp.replace('.js', '')) | |
console.info('script src:', url+'/'+temp+'\n') | |
options.map[temp] = [{ | |
require: f, | |
expose: temp.replace('.js', '') | |
}] | |
} | |
}) | |
console.info('partitioning bundle with options:\n', options) | |
var b = browserify() | |
b.plugin('partition-bundle', options) | |
b.bundle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment