swc-project / plugins

Plugins for swc, written in rust
Apache License 2.0
334 stars 55 forks source link

feat(prefresh): Add `@swc/plugin-prefresh` #326

Closed LingyuCoder closed 4 months ago

LingyuCoder commented 4 months ago

Add @swc/plugin-prefresh, which is the SWC implementation of the prefresh babel plugin.

Prefresh babel plugin is a forked equivalent of the react-refresh babel plugin difference being that we need a way to memoize createContext between HMR.

And SWC has built-in React Refresh transformation, therefore, this plugin only implements the createContext processing part and need to be used with jsc.transform.react.refresh.

For example:

{
  "jsc": {
    "experimental": {
      "plugins": [
        [
          // enable prefresh specific transformation
          "@swc/plugin-prefresh",
          {
            // the customizable preact name, default is `["preact", "preact/compat", "react"]`
            "library": ["preact-like-framework"]
          }
        ]
      ]
    },
    "parser": {
      "jsx": true
    },
    "transform": {
      "react": {
        "development": true,
        "refresh": true, // enable react refresh transformation
      }
    }
  }
}
changeset-bot[bot] commented 4 months ago

⚠️ No Changeset found

Latest commit: 8257497797f5606e3ab235ddca712e94c3bd02c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

CLAassistant commented 4 months ago

CLA assistant check
All committers have signed the CLA.