-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Integration with webpack #395
Comments
Related: #5 |
@roman01la You can dynamically build a I like your approach more than what I've tried here and there. |
@pilwon Thanks for this gist! I've found that calling There's |
@roman01la I tried to use the |
One more thing. In order to be able to pick up new native modules while webpack is running, you need to load |
@pilwon Nope, For me it looks like the whole React Native is nicely divided into separate modules, so probably some of them will go standalone to npm, |
@roman01la Thanks. There's a plan to publish packager as a standalone NPM package: #363 |
Is packager intended to live on? Personally I'd rather see packager shrink to be the bare minimum required to load a JS file into native, and then the existing features could be spun out separately and be replaceable by other existing bundling solutions. At the moment it's not entirely clear to me what is in scope / not in scope for packager - I can't even figure out how you're getting Xcode to launch it on build! 😕 |
If we can use webpack we will. For our codebase webpack is 10 times slower for us. 8 seconds per file change is a no go. I suggested to the maintainers here what could be done to make perform better #5
Ideally, we'll get to a point where you can use your tools and infrastructure regardless of what we use for core.
I assure it's a lot faster than webpack/browserify combined for bundling and sourcemaps. The only slow part if the initial file crawl. Which we have to do -- and they don't -- because our module format isn't tied to the file system.
This is the plan :)
The readme is a great place to start https://github.com/facebook/react-native/blob/master/packager/README.md |
@glenjamin Xcode has a build phase shell script command that launches packager if there's no server listening port 8081. nc -w 5 -z localhost 8081 > /dev/null 2>&1 || open $SRCROOT/../packager/launchPackager.command || echo \"Can't start packager automatically\" |
@amasad awesome answers - thanks! The faster question was whether it'd still be fast if it had all other features, but if that's a non-goal the question is irrelevant :) |
@pilwon - the bit I strugged to find was where they script is initiated from, probably just unfamiliarity with Xcode on my part |
@amasad Is |
Yeah we want to do that, but haven't had the time to figure out a better way to do it so far. Suggestions are welcome |
@vjeux Supporting UMD would make it trivial to integrate |
UMD might be a good solution, might be helpful in removing the few globals that we have, like |
Just saw this project, anyone wants to give a shot and report back? cc @mjohnston |
react-native-webpack-server basically fronts the react-native packager with webpack. The react-native code is complied with the built-in React packager, and your app code is compiled with webpack. There's a simple build phase that combines the 2 and concats source maps. The nice thing about this setup is that it opens the door for things like react hot loader. One thing that might be worth exploring for react-native is concat'ing source maps for code from an external complier (babel, typescript, etc.). I think a fairly common use case is people who want to reuse some of their existing code in a react native app, but that code requires transforms not currently supported by jstransform (let/const and property initializers come to mind). |
Thanks @mjohnston! There is an open issue for consuming source maps from custom transformers and I'll get to it soon. Your project sounds awesome, I'm going to start pointing people interested in using webpack to your project. My only minor concern is that we're currently working on a platform-independent solution for assets and the packager will play a role in that. Meaning, we don't want React Native developers to learn to have to learn the different ways to manage assets (for every platform they want to target) and just use the same method everywhere, and be able to put images with the code and even publish components to npm with images. We're still hammering out the details, but I'm sure you can follow the same approach where you're delegating to react-packager. I'll ping you once we start rolling this out and I'll write some docs. |
Sounds good @amasad. I'll try and stay in the loop with regards to the packager. I imagine that once react packager supports custom transformers (or when you switch to babel) that will satisfy the majority of webpack users. |
@mjohnston Installing 3rd party modules is the only issue i've run into with your webpack server. Most react-native modules appear to be ES6 but |
@amccloud I believe you're talking about the example project which excludes |
@mjohnston I tried that. Whitelisting the module but then webpack/babel tries to resolve the require statements in the module. Specifically i'm trying to use https://github.com/lwansbrough/react-native-camera |
@amccloud Moving the discussion over to mjohnston/react-native-webpack-server#13 |
wrt consuming source maps. Now, if you return a |
Summary: This PR removes some duplicate code by calculating with ```mainSize```/```crossSize``` and converting that to ```width``` or ```height``` at the end. See #395 . Closes facebook/yoga#396 Reviewed By: astreet Differential Revision: D4564713 Pulled By: emilsjolander fbshipit-source-id: 0b24e69cc9dc75cdf93deeb6c076dcacf134c6d8
Summary: This PR removes some duplicate code by calculating with ```mainSize```/```crossSize``` and converting that to ```width``` or ```height``` at the end. See facebook#395 . Closes facebook/yoga#396 Reviewed By: astreet Differential Revision: D4564713 Pulled By: emilsjolander fbshipit-source-id: 0b24e69cc9dc75cdf93deeb6c076dcacf134c6d8
Summary: This PR removes some duplicate code by calculating with ```mainSize```/```crossSize``` and converting that to ```width``` or ```height``` at the end. See facebook#395 . Closes facebook/yoga#396 Reviewed By: astreet Differential Revision: D4564713 Pulled By: emilsjolander fbshipit-source-id: 0b24e69cc9dc75cdf93deeb6c076dcacf134c6d8
Summary: This PR removes some duplicate code by calculating with ```mainSize```/```crossSize``` and converting that to ```width``` or ```height``` at the end. See facebook#395 . Closes facebook/yoga#396 Reviewed By: astreet Differential Revision: D4564713 Pulled By: emilsjolander fbshipit-source-id: 0b24e69cc9dc75cdf93deeb6c076dcacf134c6d8
Custom loaders is another great advantage of Webpack React Native could benefit from |
The most painless way I've found is to tell webpack to ignore native modules using
externals
config, like this. It seems good enough, but you need to keep a list of native components up-to-date and run webpack as separate process.The simplest solution is to let React Native expose a list of names of all native components, including user-defined. So it can be then used in webpack config like this:
Also I can think of a webpack loader which is a thin wrapper around packager. It should be declared as the last loader in loaders pipeline (e.g.
loaders: [ 'react-native-loader', 'babel-loader' ]
). In this case packager should only do packaging andwebpack-dev-server
will be responsible of serving bundled output, thus it should be easier to integrate React Hot Loader, which is really cool!Any thoughts?
The text was updated successfully, but these errors were encountered: