react-automata icon indicating copy to clipboard operation
react-automata copied to clipboard

react-test-renderer is included in production bundle

Open good-idea opened this issue 6 years ago • 14 comments

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 avatar Feb 27 '18 02:02 good-idea

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

good-idea avatar Feb 27 '18 02:02 good-idea

@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 avatar Aug 20 '18 11:08 edorivai

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';

edorivai avatar Aug 20 '18 11:08 edorivai

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!

MicheleBertoli avatar Aug 26 '18 10:08 MicheleBertoli

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

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

edorivai avatar Aug 26 '18 18:08 edorivai

@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

good-idea avatar Aug 26 '18 19:08 good-idea

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

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

MicheleBertoli avatar Aug 28 '18 20:08 MicheleBertoli

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.

good-idea avatar Aug 29 '18 00:08 good-idea

@good-idea I see, thanks for checking. That was possible (not recommended) before we moved to flat bundles in https://github.com/MicheleBertoli/react-automata/pull/38.

MicheleBertoli avatar Aug 29 '18 07:08 MicheleBertoli

+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.

san650 avatar Aug 29 '18 14:08 san650

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!

MicheleBertoli avatar Aug 29 '18 14:08 MicheleBertoli

I'll start working on it!

san650 avatar Aug 29 '18 19:08 san650

Hey @san650 .. any updates on this ?

Gioni06 avatar Sep 11 '18 06:09 Gioni06

Howdy all 👋

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

Check it out at #83

ctrlplusb avatar Nov 16 '18 06:11 ctrlplusb