Skip to content
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

react-test-renderer is included in production bundle #32

Open
good-idea opened this issue Feb 27, 2018 · 14 comments
Open

react-test-renderer is included in production bundle #32

good-idea opened this issue Feb 27, 2018 · 14 comments

Comments

@good-idea
Copy link

According to my webpack stats, it's adding about 55k to a production build. Is there a way to allow this to be eliminated by tree-shaking if testStatechart is not in use?

@good-idea
Copy link
Author

My apologies! I didn't do enough searching and just saw that you can do this manually with babel-plugin-transform-import

@edorivai
Copy link

@good-idea Could you elaborate on your setup? Did you manage to produce a production bundle without react-test-renderer, but with react-automata?

@edorivai
Copy link

I dove into this a little bit more. Looking through the source code here, I would guess the idea is that react-test-renderer will get removed by tree shaking. However, at least in my setup, it is not:

image

Note that I am not importing testStateMachine in my production code.

We're running a setup with Typescript, Babel, and Webpack. I can see in my bundle stats that the react-automata.es.js file is imported, but the test renderer does not get tree-shaken away.

So my question: what is the recommended way to use react-automata, but prevent react-test-renderer from being included in my bundle.

Personally, I always appreciate it if there is a way to manually selectively import parts of a library, like so:

import { State } from 'react-automata/State';

@MicheleBertoli
Copy link
Owner

Thank you very much @good-idea @edorivai to discuss about this.

I was thinking about separating the packages, like:

import { Action, State, withStateMachine } from 'react-automata'

and:

import { testStateMachine } from 'react-automata-test-utilities'

What do you think?

Also, if someone has experience creating a monorepo with Learn and Yarn Workspaces is more than welcome to submit a PR : )

Than you very much!

@edorivai
Copy link

That solution sounds good to me. Any particular reason you won't just expose it like this:

import { testUtility } from 'react-automata/testUtility';

@good-idea
Copy link
Author

@edorivai I'm digging through my projects but can't find the config file where I implemented this, sorry! I'll try to set it up with a repo sometime this week

@MicheleBertoli
Copy link
Owner

@edorivai separate packages would allow us to define different dependencies.

Thank you very much, @good-idea, that would be awesome.

@good-idea
Copy link
Author

Hey all, sorry, I gave this a shot and wasn't able to get it working - it requires that the bundled NPM package has a structure like lib/moduleName.

I'm not sure where or how I had this working. (Maybe I actually didn't?) This was also back in february, when React-automata was at an earlier version.

@MicheleBertoli
Copy link
Owner

@good-idea I see, thanks for checking. That was possible (not recommended) before we moved to flat bundles in #38.

@san650
Copy link

san650 commented Aug 29, 2018

+1 to have separate projects for testing helpers. Having react-test-rendered pulled in into production builds is a blocker for us.

Can I help making this happen? I could try updating this repo to be a monorepo for both libraries.

@MicheleBertoli
Copy link
Owner

Yes, please @san650.
Ping me anytime if you need support, and I'll be more than happy to review a PR.
Thank you very much!

@san650
Copy link

san650 commented Aug 29, 2018

I'll start working on it!

@Gioni06
Copy link

Gioni06 commented Sep 11, 2018

Hey @san650 .. any updates on this ?

@ctrlplusb
Copy link

Howdy all 👋

I've made great progress on the Lerna Monorepo migration.

Check it out at #83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants