-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Documentation on using metro bundler #1257
Comments
I agree that it will be good once a single bundler can be used for all platforms. And Metro has some nice perf benefits over webpack (laziness). But this is something for the Metro project to eventually document when it is considered stable enough for public consumption. It's not something I can do or promote at this stage. I'd encourage you to reach out to the Metro team if you'd like to discuss this with them, or get pointers to what would be involved! |
@necolas - Sounds good, thanks for the info. So, as of at least the date of our discussion here, best bet is to prefer webpack, eh? |
I managed to get Metro bundling react-native-web with the following steps: Add the following metro.config.js to the root project directory, which is based off the react-native-windows config (https://github.com/microsoft/react-native-windows/blob/3bab85d89f4b01adc59b26a3e523fc4fe6b4ac93/vnext/local-cli/generator-windows/templates/metro.config.js)
Edit the function getSha1 in node_modules\metro\src\node-haste\DependencyGraph.js to match the following, as described in facebook/metro#330
You can then create a bundle using the command Edit:
|
@howlettt thanks for sharing, this worked well for me as well :) I had to add "assetRegistryPath" to the transformer, since some of my libraries include images. Adding the path
and changing the transformer
In my case I also had to replace "react-native-linear-gradient" with "react-native-web-linear-gradient" using the same method you used to replace "react-native" with "react-native-web". |
@howlettt does this implementation also allow for Fast Refresh to be used for web? |
@tehOPEologist no, you have to manually refresh the page after each change |
ok, was hoping there's a metro for web solution that uses fast refresh =\ |
Updated steps for react-native 0.62 Step 1Add a new file metroWeb.config.js to the root project directory with content:
Step 2Edit the getSha1 function in both the following files to fix facebook/metro#330
by changing
to
Step 3You can then create a bundle using the command:
|
But I don't have this file |
@mrKorg looks like they renamed it to exclusionList https://github.com/facebook/metro/blob/master/packages/metro-config/src/defaults/exclusionList.js |
Hi. edit: |
@samaneh-kamalian I just tested this locally with react-native 0.64.0 & react-native-web 0.15.7 and it works. The only change I made was replacing Check these links out, they may help |
Thanks for your reply. |
@samaneh-kamalian I was able to resolve the issue. The problem was that those files should not have been included from The reason this was happening is because of a broken blacklist regular expression in the Metro configuration. It might have been working for others because they are on Windows, but I am on a Mac (just a guess). Here is the new configuration that works for me. Please note I have simply hard-coded the blacklist path, the regular expression still needs to be fixed. I have also shown how to use the bundle and load it from the top-level The following applies to a fresh react-native 0.71 app.
Rest of the instructions are same as described by @howlettt above. Note the change in blacklist import file name. How to use the created JS bundle:
|
Are there some methods to make it working with hot reload? |
I'm confused -- are these steps still needed today? The Expo docs make it sound really simple to add the web platform, but it doesn't really work. |
Hello. I am, trying to setting up my already existing react-native project (without Expo) with metro bundler but getting the following:
My custom config metro.config.web.js looks working and is used, but it seems like I have not installed some additinal packages or something esle.
|
I'm not sure if it's a well supported path or if there are strong arguments for preferring webpack, but I'd love to see more docs and information about using metro.
My goal here would be to leverage consistency of build tooling for my react native vs. react native web projects. But I also know that web projects tend to require a lot of the magic that webpack offers which maybe metro doesn't have?
The text was updated successfully, but these errors were encountered: