diff --git a/.changeset/proud-clouds-explain.md b/.changeset/proud-clouds-explain.md new file mode 100644 index 0000000000..15e4373b2d --- /dev/null +++ b/.changeset/proud-clouds-explain.md @@ -0,0 +1,5 @@ +--- +'@xstate/react': minor +--- + +Added UMD bundle. diff --git a/packages/xstate-react/README.md b/packages/xstate-react/README.md index 31bbad2216..ed6b7329f2 100644 --- a/packages/xstate-react/README.md +++ b/packages/xstate-react/README.md @@ -29,6 +29,22 @@ npm i xstate @xstate/react ``` +**Via CDN** + +```html + +``` + +By using the global variable `XStateReact` + +or + +```html + +``` + +By using the global variable `XStateReactFSM` + 2. Import the `useMachine` hook: ```js diff --git a/packages/xstate-react/package.json b/packages/xstate-react/package.json index fdc2c4c318..2c4ddf3521 100644 --- a/packages/xstate-react/package.json +++ b/packages/xstate-react/package.json @@ -26,6 +26,7 @@ "files": [ "lib/**/*.js", "lib/**/*.d.ts", + "dist/**/*.js", "es/**/*.js", "es/**/*.d.ts" ], @@ -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" }, @@ -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": "*" diff --git a/packages/xstate-react/rollup.config.js b/packages/xstate-react/rollup.config.js new file mode 100644 index 0000000000..155b288c35 --- /dev/null +++ b/packages/xstate-react/rollup.config.js @@ -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$/] })] + }; +} + +export default [ + createUmdConfig({ + 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' + }) +];