Uh oh!
There was an error while loading. Please reload this page.
Use babel-plugin-react-native-web - #4125
Conversation
necolas
commented
Mar 8, 2018
You might want to keep the webpack alias in there for people installing node modules, as CRA won't run Babel over everything and can't be configured to so so. |
paularmstrong
commented
Mar 8, 2018
Can you give an example of this? I don't understand the problem. Sounds like advanced usage in which someone would want to eject. |
necolas
commented
Mar 8, 2018
CRA doesn't run Babel over node modules. If someone installs a package that imports "react-native" it will throw an error unless the module is passed through Babel, or the webpack alias is in place |
iansu
commented
Mar 8, 2018
This seems reasonable to me. In the future we plan to compile node modules so we can remove the alias then. Are there any issues with using the alias and this plugin together? |
Ah, didn't think of that case, since I haven't used any external modules that import @iansu the babel plugin works over both |
necolas
commented
Mar 8, 2018
IIRC, Dan said that wouldn't involve compiling all dependencies |
49ef620 to
6a1d05fCompareandriijas
commented
Mar 19, 2018
Webpack 4 has built-in tree shaking rather than relying on uglifyjs which improves code elimination efficiently. I wonder if these extra kb will be shaken when we upgrade. |
necolas
commented
Mar 19, 2018
Doesn't that require an entire package to be marked as having no side effects? |
necolas
commented
May 25, 2018
This can probably be closed as webpack will now tree-shake the ES modules |
Fixesnecolas/react-native-web#629
Problem: Current support for react-native-web uses a webpack alias. This causes the entirety of react-native-web to be bundled when building for production. Unfortunately, this means that every single module, used or not, will be bundled. This can grow app sizes by upwards of 50KiB without any benefit.
Solution: react-native-web publishes a babel plugin that handles aliasing of
react-native -> react-native-weband also swaps the import paths so that it doesn't import the entire app, but just the specific modules used. Info at necolas/react-native-web/packages/babel-plugin-react-native-webTest Plan:
yarn create-react-app testcd test && yarn add react-native-webimport { View } from 'react-native';toApp.jsand use it in place of anydivyarn testyarn startyarn buildyarn ejectand repeat steps 4-6NOTE: AppVeyor failure looks like a fluke. Can anyone verify?