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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-clouds-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xstate/react': minor
---

Added UMD bundle.
16 changes: 16 additions & 0 deletions packages/xstate-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
npm i xstate @xstate/react
```

**Via CDN**

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

By using the global variable `XStateReact`

or

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

By using the global variable `XStateReactFSM`

2. Import the `useMachine` hook:

```js
Expand Down
6 changes: 5 additions & 1 deletion packages/xstate-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"files": [
"lib/**/*.js",
"lib/**/*.d.ts",
"dist/**/*.js",
"es/**/*.js",
"es/**/*.d.ts"
],
Expand All @@ -35,7 +36,7 @@
},
"scripts": {
"clean": "rm -rf dist lib tsconfig.tsbuildinfo",
"build": "tsc && tsc --outDir es --module es2015",
"build": "tsc && tsc --outDir es --module es2015 && rollup -c",
"test": "jest",
"prepublish": "npm run build && npm run test"
},
Expand Down Expand Up @@ -71,6 +72,9 @@
"lerna-alias": "3.0.3-0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"rollup": "^1.26.3",
"rollup-plugin-terser": "^5.1.2",
"rollup-plugin-typescript2": "^0.25.2",
"ts-jest": "^26.4.0",
"typescript": "^4.1.2",
"xstate": "*"
Expand Down
41 changes: 41 additions & 0 deletions packages/xstate-react/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';

function createTSCofig() {
return typescript({
tsconfigOverride: {
compilerOptions: {
declaration: false
}
}
});
}

function createUmdConfig({ input, output: file, name }) {
return {
input,
output: {
file,
format: 'umd',
name,
globals: {
xstate: 'XState',
'@xstate/react': 'XStateReact'
}
},
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

};
}

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

name: 'XStateReact',
input: 'src/index.ts',
output: 'dist/xstate-react.umd.min.js'
}),
createUmdConfig({
name: 'XStateReactFSM',
input: 'src/fsm.ts',
output: 'dist/xstate-react-fsm.umd.min.js'
})
];