How to create a tree shaken component library in React using webpack - javascript

Is there any approach to create a treeshaken library using React using webpack, most of them suggesting with Rollup but our existing project was bundled with webpack. The problem with current project is, its not treeshaken library, now the required is to make the project as a treeshaken component library.
I tried with create react app and ejecting it, but this solution does not worked

Related

Deploying React JS Projects

Is it possible to use a build version of React JS project within a JavaScript project, if it is, then can it be done?

use configuration we get from create-react-app or create our own custom webpack and babel configuration and install react

Which would be a better option when developing large React Applications ? Using the create-react-app and the default webpack and babel configurations provided by it or creating a custom webpack and babel configurations and install react packages ?
I have developed small applications in react using create-react-app and now wants understand every small part starting from webpack and babel. Do big companies use webpack and babel or simply create-react app ?
You can use create-react-app and as soon as you feel like yo need to modify these files you do it. Create-react-app is a good way to start and those files can be edited whenever you need to!

How do I create a simple Vue project without a big app.js file?

I want to create a Vue app, so I started by using the Vue CLI to do so, but the app.js bundle is 1.2 MB before I've even really done anything. I'd like to bring that way down, as I really don't want/need all the stuff that is being bundled into that file.
Specifically, I would like to have a Vue app with Babel so I can transpile ES6, Webpack for bundling everything, and Sass for the CSS.
What's the easiest way to create a Vue project like this without all the bloat that occurs when I use the Vue CLI? And what I'm specifically looking for is instructions on how to install (I'm assuming just use npm) all of these things and then setting them up to work together, which is the part I'm stuck on.
I can set up Webpack by itself, and I can set up Vue by itself, but I don't know how to get Webpack to compile Vue files, and I don't know how to set up Babel to work with all of this and transpile everything. Thank you.

Can I use reactJS library in react-native?

Well, this might be a silly question but I want to clarify the reason.
React-Native imports nodeJS libraries, so I think it is possible to use reactJS library as well though reactJS includes pure html components.
Can react native recognize reactJS components including html?
react library actually does not have anything related to Browser DOM HTML. Anything related to it separated into react-dom package. React Native does not and cannot use this library, because you don't have DOM underneath a react native application. However you can use most of the code/functionality you wrote for your mobile app in the browser, if you install necessary transpiling library. This is possible because react native defines some primitive components that can be ported to almost any platform.
If you still want to use just HTML to render inside react native, you may use WebView for it.
Usually libraries built specifically for other platforms will not work with React Native. Examples include react-select which is built for the web and specifically targets react-dom, and rimraf which is built for Node.js and interacts with your computer file system. Other libraries like lodash use only JavaScript language features and work in any environment. You will gain a sense for this over time, but until then the easiest way to find out is to try it yourself. You can remove packages using npm uninstall if it turns out that it does not work in React Native.
-- source: React native official docs

How can I 'swap' react for react/addons in my application?

I want to use the Perf stuff. It seems that if I do:
var React = require('react/addons');
in my own modules then libraries (react-bootstrap, react-router etc.) end up using another copy of plain react and things break. I am using browserify.
Is there a fix or another way to do this?
Requiring react and react/addons will give you the same object. react/addons requires the same module that react does (lib/React), and react/addons even mutates that object so that anyone requiring react will get the addons as well.
If you end up with multiple versions of React in your bundle, it's because the libraries you use have react as a dependency instead of a peer dependency. You should use npm dedupe to avoid that. But react-router has react as a peer dependency, so react-router will get the same react module instance as your module (with the addons). Don't know about the other packages you use that depend on React though.
It turns out the problem was with my gulpfile. Tx for the comments about looking for a browserify shim that lead me to the solution:
My browserify task (from React JS workflow, part 2) builds separate vendors.js (libs) and main.js (my app) bundles during development using browserify.external(..) to exclude the libs from main.js. I just had to add "react/addons" as an external lib along with "react".
The issue is explained here:
https://github.com/substack/node-browserify/issues/1161

Categories