Last active
August 10, 2017 14:32
-
-
Save kristoferjoseph/921160c70967e31dbcf45b4642e73b69 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() |
Added the ability to pass a folder of directories with package.json
files included
Screens
|--Home
|--index.js
|--package.json
|-- { main: index.js, name: 'home' }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your
package.json
you can use them in the"scripts"
section like so:"local": "./scripts/build ./index.js ./screens/*.js -o=assets -m=./index.js"
"prod": "./scripts/build ./index.js ./screens/*.js -o=assets -m=./index.js --url='http://remote.url.like.s3'"