-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bundle script instead of curl #851
Conversation
Suggestion: http.get(options, function(res) {
var stream = fs.createWriteStream(OUT_PATH);
res.pipe(stream);
}); |
Thanks @drkibitz, took your suggestion. |
@@ -14,7 +15,8 @@ function printUsage() { | |||
'', | |||
'Commands:', | |||
' start: starts the webserver', | |||
' install: installs npm react components' | |||
' install: installs npm react components', | |||
' build: builds the javascript bundle for offline use' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean bundle
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I was actually debating build
vs bundle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it bundle
, we are currently thinking about new build
command that would compile ObjC code so you don't even have to run Xcode
Thanks, that's really handy! We use something similar internally, but it's tied to our infra and build tools. Actually react packager exposes API to create offline bundle without running the server, see And please update the comments in |
@frantic I'll have to update multiple projects we depend on, and hopefully it doesn't cause any performance degradation (it will for people with lower ulimits). But I'm fine with that. |
I've updated the patch. It now uses ReactPackager and does not need the server running. Some todos:
|
@arthuralee - great job! I don't think you should be solving ulimit issue in this PR, that's a more general problem that might be relevant to other tools as well. We should probably either switch to I'll take a closer look and merge this in soon. |
fs.writeFile(OUT_PATH, bundle.getSource({ | ||
inlineSourceMap: false, | ||
minify: flags.minify | ||
}), function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please handle the error here and show some helpful error message.
Thanks @frantic, sounds good. I've added error handling to Maybe we should address the ulimit problem in a separate issue. I can open one if there isn't one yet. |
|
||
console.log('Building package...'); | ||
ReactPackager.buildPackageFromUrl(options, url) | ||
.then(function(bundle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use done
to make sure if ReactPackager.buildPackageFromUrl
throws the error is reported.
Added bundle script Pipe http response straight to file Used ReactPackager directly, minor fixes Added error handling to fs.writeFile Changed .then to .done
Makes sense, updated. I also updated the website docs. |
Awesome thanks! If you are willing to make this even better, here is a suggestion - add a step to end-to-end tests that calls |
Great to see this merged! Will look into e2e tests. :) |
👯 |
Nice work! When will this be released? Just noticed the live Docs has updated but the cli tool hasn't. May introduce confusions. 😄 |
Good point. It's already been merged so its available on |
does bundle command included correctly in 0.4.1? ZapCourier [master●] % react-native bundle
Building package...
/Users/romanonthego/Code/ZapCourier/node_modules/react-native/node_modules/bluebird/js/main/promise.js:626
throw e;
^
Error: EMFILE, open '/Users/romanonthego/Code/ZapCourier/node_modules/react-native/node_modules/react-tools/src/browser/ui/dom/ViewportMetrics.js' every time. on same notice - why react |
Thanks @romanonthego. I will look into this today. There have been a lot of new changes since this has been merged, so it might have broken something. Looks like I should've gone into e2e tests earlier! In the meantime, feel free to create an open issue for this. As far as I know, |
@romanonthego I could not repro the error. I tested both an empty project and an existing project. To further verify this, the file in question ( |
@romanonthego - the problem is caused by too many files and low open files limit per process. Run @arthuralee, it's hard to repro because different environments might have different ulimits, also some users will have more js files in node_modules and will hit the bug, wheres vanilla react-native can fit in standard 256 limit. |
I've just cleaned npm cache and reinstall all global packages ( @frantic i've used this fix and it didn't help at the moment (I've encountered this bug before, although it was in form |
This is an initial stab at creating a node-based bundling script so that you don't have to manually run
curl
. My idea was to have it as a command underreact-native
. It allows command line flags fordev
andminify
. It still requires the server to be up, but I hope to detect that and maybe automatically run the server in the future.Wondering if this is a good idea and if so, the right approach.