{"id":13834681,"url":"https://github.com/elsassph/react-hot-ts","last_synced_at":"2025-04-12T15:07:12.156Z","repository":{"id":34365274,"uuid":"176035921","full_name":"elsassph/react-hot-ts","owner":"elsassph","description":"React hot reload for TypeScript and Webpack/ts-loader or fuse-box","archived":false,"fork":false,"pushed_at":"2023-01-07T03:52:25.000Z","size":1444,"stargazers_count":27,"open_issues_count":18,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-09T03:17:42.215Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elsassph.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-16T23:33:10.000Z","updated_at":"2023-05-17T09:06:00.000Z","dependencies_parsed_at":"2023-01-15T06:36:30.444Z","dependency_job_id":null,"html_url":"https://github.com/elsassph/react-hot-ts","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsassph%2Freact-hot-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsassph%2Freact-hot-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsassph%2Freact-hot-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsassph%2Freact-hot-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elsassph","download_url":"https://codeload.github.com/elsassph/react-hot-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224732187,"owners_count":17360467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T14:00:50.961Z","updated_at":"2024-11-15T05:18:03.191Z","avatar_url":"https://github.com/elsassph.png","language":"TypeScript","funding_links":[],"categories":["Transformers"],"sub_categories":["React"],"readme":"# React hot loader for TypeScript\n\nA lightweight, Typescript-native, Babel-free, plugin-free, implementation of [react-hot-loader][1].\n\nAdd React hot-reload (live update without losing state) in your TypeScript projects!\n\n## Supported bundlers\n\n- [Webpack][2] + [ts-loader][3]\n- [FuseBox][4]\n\n## Features\n\n- Compile-time transformation is done using a TypeScript compiler hook,\n- Supports both React component classes and functional components,\n- Reliable hot-reload feature based on Dan Abramov's [react-proxy][5] (for ES5) or [react-stand-in][6] for ES6 (needs alias),\n- Support both ES5 and ES6 compilation targets.\n\n## Bonus\n\n- Rewrites arrow functions to be hot-reload friendly (can be opt-out),\n- Ensures React functions and classes have a \"display name\", for enhanced debugging experience.\n\n[1]: https://github.com/gaearon/react-hot-loader\n[2]: https://webpack.js.org\n[3]: https://github.com/TypeStrong/ts-loader\n[4]: https://fuse-box.org/\n[5]: https://github.com/gaearon/react-proxy\n[6]: https://github.com/theKashey/react-stand-in\n\n## Installation\n\n```\nnpm install react-hot-ts -D\n```\nOr\n```\nyarn add react-hot-ts -D\n```\n\n## Webpack configuration\n\nJust 2 steps:\n\n1. Make your Webpack configuration \"hot\" for development\n\n    See guide: https://webpack.js.org/guides/hot-module-replacement/#enabling-hmr\n\n2. Configure the TypeScript loader with a custom transformer (you can keep it in your production builds)\n\n```javascript\nconst rhTransformer = require('react-hot-ts/lib/transformer');\n/*...*/\n\nmodule.exports = {\n    /*...*/\n    rules: [\n        {\n            test: /\\.tsx?$/,\n            use: [{\n                loader: 'ts-loader',\n                options: {\n                    // enable TS transformation\n                    getCustomTransformers: {\n                        before: [ rhTransformer() ]\n                    }\n                }\n            }]\n        }\n        /*...*/\n    ]\n    /*...*/\n}\n```\n\n### Transformer options\n\nAlthough they shouldn't be needed for normal use cases, the transformers has a few options:\n\nUsage: `rhTransformer(options)`\n\nWhere `options` is an object with the following optional fields:\n\n- `disable`: force release mode, disregarding `NODE_ENV` value,\n- `keepArrows`: opt-out of arrow functions rewriting; this can avoid a lot of extra code (and maybe subtle issues) when targeting ES5 instead of ES6,\n- `rhRuntime`: (advanced) specify an alternative module to be required for the client hot-loading runtime logic.\n\nExample: `rhTransformer({ keepArrows: true })`\n\n### Attention NODE_ENV\n\nYou must set the `NODE_ENV` environment (e.g. `process.env.NODE_ENV`) to `\"production\"` to disable the transform.\nYou will see this message in the console:\n```\n[react-hot-ts] disabled for production\n```\n*Note: Webpack's `mode` is [not sufficient](https://github.com/webpack/webpack/issues/7074).*\n\n## React usage\n\nOnce the compiler transformation is in place, you just need to wrap your root `ReactDOM.render` call:\n\n```typescript\nimport { hot } from 'react-hot-ts';\n\nhot(module)( ReactDOM.render(\u003cApp/\u003e) );\n```\n\nWhen building for release, only the HMR runtime will be replaced by a no-op.\n\nNow run Webpack dev server and enjoy live component updates!\n\n## Known issues\n\n### Targeting ES6\n\nIf you target ES6 with the TypeScript compiler, you will run into runtime errors like:\n\n    Uncaught TypeError: Cannot convert undefined or null to object\n\nThe reason is that `react-proxy` isn't ES6-friendly, and the solution is to install `react-stand-in`\nand add an alias in your bundler to remap the former:\n\n- https://webpack.js.org/configuration/resolve/#resolvealias\n- https://fuse-box.org/docs/development/configuration#alias\n\n### Only `.tsx` files are considered\n\nIf you use `.ts` and manual `React.createComponent` code, it won't be registered for HMR.\n\n**Workaround** is to use `.tsx` ;)\n\n### Passing non-exported React classes/functions references\n\nNon-exported class or function won't be reloaded if their reference is kept outside the module.\n\n```typescript\n// A.js\nclass A extends Component {...};\nexport function provideA() {\n    return A;\n}\n\n// B.js\nimport {provideA} from 'A';\nexport class B extends Component {\n    private ARef;\n    constructor() {\n        this.ARef = provideA();\n    }\n    render() {\n        return \u003cARef/\u003e;\n    }\n}\n```\n\n**Workaround** is to export the class/function even if it won't be used from exports.\n\n## ISC License\n\nCopyright 2019 Philippe Elsass\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felsassph%2Freact-hot-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felsassph%2Freact-hot-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felsassph%2Freact-hot-ts/lists"}