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

Add UMD bundle for @xstate/react. #1738

Merged
merged 7 commits into from
Dec 19, 2020
Merged

Conversation

dimitardanailov
Copy link
Contributor

The pull request is based on #1108.

The pull request should close the following issue: #1736

@changeset-bot
Copy link

changeset-bot bot commented Dec 17, 2020

🦋 Changeset detected

Latest commit: c7422c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@xstate/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@davidkpiano davidkpiano requested a review from Andarist December 17, 2020 19:10
@davidkpiano
Copy link
Member

Thanks @dimitardanailov! Can you also add a changeset?

  1. yarn changeset
  2. Enter a changeset to make a minor change for @xstate/react, describing that you're adding UMD bundles.

@dimitardanailov
Copy link
Contributor Author

@davidkpiano

Please review my commit: b4f8dd4

.changeset/proud-clouds-explain.md Outdated Show resolved Hide resolved
globals: {
xstate: 'XState',
'@xstate/react': 'XStateReact',
'@react/composition-api': 'reactCompositionApi'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't exist, could you remove this entry?

createUmdConfig({
name: 'XStateReact',
input: 'src/index.ts',
output: 'dist/xstate-react.min.js'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what will be generated in v5 by Preconstruct and this ain't configurable there, so to avoid a small breaking change in the future we can already name this file this:

Suggested change
output: 'dist/xstate-react.min.js'
output: 'dist/xstate-react.umd.min.js'

}

export default [
createUmdConfig({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in v5 we won't be generating unminified UMD bundles, so let's drop this for now

'@react/composition-api': 'reactCompositionApi'
}
},
plugins: [createTSCofig(), terser({ include: [/^.+\.min\.js$/] })]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned in the other comment - let's just focus on producing minified bundles

createUmdConfig({
name: 'XStateReactFSM',
input: 'src/fsm.ts',
output: 'dist/xstate-react.fsm.min.js'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the other comment about v5 - we should be naming this file like this:

Suggested change
output: 'dist/xstate-react.fsm.min.js'
output: 'dist/xstate-react-fsm.umd.min.js'

**Via CDN**

```html
<script src="https://unpkg.com/@xstate/react/dist/xstate-react.min.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after adjusting configs please remember about adjusting those URLs here

@dimitardanailov
Copy link
Contributor Author

@Andarist

Thank you very much for the additional advices. I've created three new commits. Please review my improvements.

@Andarist Andarist merged commit dd98296 into statelyai:master Dec 19, 2020
@Andarist
Copy link
Member

Thanks!

@dimitardanailov
Copy link
Contributor Author

@Andarist and @davidkpiano

Thank you very much for the collaboration. I'd like to share: What I found. Before that: I'd like to give you access to my playground area:

branch: xstate-react-umd -> https://github.com/dimitardanailov/react-components/tree/xstate-react-umd
Component:
https://github.com/dimitardanailov/react-components/blob/xstate-react-umd/packages/d3-tree-collapsible/app/components/D3Tree.js

The component throws an error if the import is:

const { useMachine } = XStateReact

The error is: react-hot-loader.development.js:297 ReferenceError: process is not defined

Screen Shot 2020-12-19 at 10 59 03 PM

Screen Shot 2020-12-19 at 11 05 11 PM

My recommendation is: https://www.npmjs.com/package/@rollup/plugin-replace
The package is able to replace string sections in the particular file.

What do you think ?

@Andarist
Copy link
Member

Ah - yes. This is the appropriate approach. I've missed that this will be required during the code review. Are you willing to prepare a PR with the fix?

@dimitardanailov
Copy link
Contributor Author

@Andarist

Please review my pull request:
#1756

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

Successfully merging this pull request may close these issues.

3 participants