forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bundle command using ReactPackager
Added bundle script Pipe http response straight to file Used ReactPackager directly, minor fixes Added error handling to fs.writeFile Changed .then to .done
- Loading branch information
1 parent
3e8b41f
commit c13646f
Showing
3 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var http = require('http'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
var blacklist = require('../packager/blacklist.js'); | ||
var ReactPackager = require('../packager/react-packager'); | ||
|
||
var OUT_PATH = 'iOS/main.jsbundle'; | ||
|
||
function getBundle(flags) { | ||
|
||
var options = { | ||
projectRoots: [path.resolve(__dirname, '../../..')], | ||
transformModulePath: require.resolve('../packager/transformer.js'), | ||
assetRoots: [path.resolve(__dirname, '../../..')], | ||
cacheVersion: '2', | ||
blacklistRE: blacklist('ios') | ||
}; | ||
|
||
var url = '/index.ios.bundle?dev=' + flags.dev; | ||
|
||
console.log('Building package...'); | ||
ReactPackager.buildPackageFromUrl(options, url) | ||
.done(function(bundle) { | ||
console.log('Build complete'); | ||
fs.writeFile(OUT_PATH, bundle.getSource({ | ||
inlineSourceMap: false, | ||
minify: flags.minify | ||
}), function(err) { | ||
if (err) { | ||
console.log(chalk.red('Error saving bundle to disk')); | ||
throw err; | ||
} else { | ||
console.log('Successfully saved bundle to ' + OUT_PATH); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function showHelp() { | ||
console.log([ | ||
'Usage: react-native bundle [options]', | ||
'', | ||
'Options:', | ||
' --dev\t\tsets DEV flag to true', | ||
' --minify\tminify js bundle' | ||
].join('\n')); | ||
process.exit(1); | ||
} | ||
|
||
module.exports = { | ||
init: function(args) { | ||
var flags = { | ||
help: args.indexOf('--help') !== -1, | ||
dev: args.indexOf('--dev') !== -1, | ||
minify: args.indexOf('--minify') !== -1 | ||
} | ||
|
||
if (flags.help) { | ||
showHelp(); | ||
} else { | ||
getBundle(flags); | ||
} | ||
} | ||
} |
This file contains 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