react-automata
react-automata copied to clipboard
react-test-renderer is included in production bundle
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?
My apologies! I didn't do enough searching and just saw that you can do this manually with babel-plugin-transform-import
@good-idea Could you elaborate on your setup? Did you manage to produce a production bundle without react-test-renderer
, but with react-automata
?
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:
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';
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!
That solution sounds good to me. Any particular reason you won't just expose it like this:
import { testUtility } from 'react-automata/testUtility';
@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
@edorivai separate packages would allow us to define different dependencies.
Thank you very much, @good-idea, that would be awesome.
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 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.
+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.
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!
I'll start working on it!
Hey @san650 .. any updates on this ?
Howdy all 👋
I've made great progress on the Lerna Monorepo migration.
Check it out at #83