Skip to content

Commit

Permalink
feat: hot module replacement
Browse files Browse the repository at this point in the history
- now supports HMR
- limitations
  - in node_modules/* modules are not supported HMR yet.
- custom runtime module system by `swc-plugin-global-module`
  - https://github.com/leegeunhyeok/swc-plugin-global-module

close #38
  • Loading branch information
leegeunhyeok committed Dec 16, 2023
1 parent e5e3048 commit a36f280
Show file tree
Hide file tree
Showing 67 changed files with 1,704 additions and 399 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ module.exports = {
'no-console': 'off',
},
},
{
files: ['packages/hmr/lib/runtime/*.ts'],
rules: {
'no-console': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
},
},
{
files: ['packages/jest/lib/**/*.ts'],
rules: {
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- 💾 In-memory & Local File System Caching
- 🎨 Flexible & Extensible
- 🔥 Supports JSC & Hermes Runtime
- 🔄 Supports Live Reload
- 🔄 Supports HMR & Live Reload
- 🐛 Supports Debugging(Flipper, Chrome Debugger)
- 🌍 Supports All Platforms(Android, iOS, Web)
- ✨ New Architecture Ready
Expand Down
31 changes: 23 additions & 8 deletions docs/pages/configuration/basic-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ exports.default = {};
By default, follow the configuration below.

```js
/**
* @type {import('@react-native-esbuild/core').Config}
*/
exports.default = {
cache: true,
logger: {
Expand All @@ -28,13 +31,6 @@ exports.default = {
assetExtensions: [/* internal/lib/defaults.ts */],
},
transformer: {
jsc: {
transform: {
react: {
runtime: 'automatic',
},
},
},
stripFlowPackageNames: ['react-native'],
},
web: {
Expand Down Expand Up @@ -68,7 +64,6 @@ Resolver configurations.

Transformer configurations.

- `transformer.jsc`: [jsc](https://swc.rs/docs/configuration/compilation) config in swc.
- `transformer.stripFlowPackageNames`: Package names to strip flow syntax from (Defaults to `['react-native']`)
- `transformer.fullyTransformPackageNames`: Package names to fully transform with [metro-react-native-babel-preset](https://github.com/facebook/react-native/tree/main/packages/react-native-babel-preset) from
- `transformer.additionalTransformRules`: Additional transform rules. This rules will be applied before phase of transform to es5
Expand All @@ -90,6 +85,15 @@ Additional Esbuild plugins.

For more details, go to [Custom Plugins](/configuration/custom-plugins)

### experimental

<Callout>
Experimental configurations.
</Callout>

- `experimental.hmr`: Enable HMR(Hot Module Replacement) on development mode. (Defaults to `false`)
- For more details and limitations, go to [Hot Module Replacement](/limitations/hot-module-replacement).

## Types

<details>
Expand Down Expand Up @@ -209,6 +213,17 @@ interface Config {
* Additional Esbuild plugins.
*/
plugins?: EsbuildPlugin[];
/**
* Experimental configurations
*/
experimental?: {
/**
* Enable HMR(Hot Module Replacement) on development mode.
*
* Defaults to `false`.
*/
hmr?: boolean;
};
/**
* Client event receiver
*/
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ And create `react-native-esbuild.js` to project root.
exports.default = {};
```

for more details, go to [Configuration](/configuration/basic).
for more details, go to [Basic Configuration](/configuration/basic-configuration).

## Native Setup

Expand Down
5 changes: 0 additions & 5 deletions docs/pages/limitations/hot-module-replacement.md

This file was deleted.

30 changes: 30 additions & 0 deletions docs/pages/limitations/hot-module-replacement.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Callout } from 'nextra/components'

# Hot Module Replacement

<Callout type="warning">
HMR(Hot Module Replacement) is experimental.
</Callout>

esbuild doesn't currently support Hot Module Replacement(HMR).

So, I working hard for implement custom HMR and it's partially available as an experimental feature.

You can enable HMR by `experimental.hmr` set to `true` in your configuration file.

```js
/**
* @type {import('@react-native-esbuild/core').Config}
*/
exports.default = {
// ...
experimental: {
hmr: true,
},
};
```

and here are some limitations.

- Detects changes in the `<projectRoot>/*` only.
- Changes detected in `<projectRoot>/node_modules/*` will be ignored and fully refreshed after rebuild.
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ yarn-error.log
!.yarn/sdks
!.yarn/versions

# @swc
.swc

# @react-native-esbuild
.rne
.swc
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions example/react-native-esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ exports.default = {
],
},
},
experimental: {
hmr: true,
},
};
Loading

1 comment on commit a36f280

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage report

St.
Category Percentage Covered / Total
🔴 Statements 14.72% 328/2228
🔴 Branches 13.92% 82/589
🔴 Functions 9.76% 65/666
🔴 Lines 14.06% 298/2119

Test suite run success

83 tests passing in 10 suites.

Report generated by 🧪jest coverage report action from a36f280

Please sign in to comment.