Skip to content

Code size when using custom preview #131

Answered by fwouts
sr258 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @sr258, that's an excellent question.

In React Preview, preview is implemented as a no-op function (see https://reactpreview.com/docs/features/custom-previews), so as long as webpack is configured to run tree shaking, that code shouldn't end up in your production bundle, unless you do something like:

preview(MyComponent, {
  foo: somethingWithSideEffects()
});

In this particular case, webpack would be right not to eliminate the side effects (as would effectively modify application behaviour), and it would indeed have an impact on your bundle.

In Preview.js (which will soon replace React Preview), setupPreviews is also implemented as a no-op function, but it allows you to pass a functi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sr258
Comment options

@fwouts
Comment options

Answer selected by fwouts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants