Git Product home page Git Product logo

isabella232 / babel-plugin-transform-react-hot-loader-wrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sourcegraph/babel-plugin-transform-react-hot-loader-wrapper

0.0 0.0 0.0 1.21 MB

Wraps all exported React components (whose names match the configured pattern) with react-hot-loader to enable hot-reloading, even if the React components are spread across Webpack chunks using code splitting.

License: Apache License 2.0

JavaScript 11.76% TypeScript 88.24%

babel-plugin-transform-react-hot-loader-wrapper's Introduction

babel-plugin-transform-react-hot-loader-wrapper

npm downloads build codecov code style: prettier semantic-release

Wraps all exported React components (whose names match the configured pattern) with react-hot-loader to enable hot-reloading, even if the React components are spread across Webpack chunks using code splitting.

For example, this source file:

import React from 'react'

export const A = () => <p>a</p>

becomes:

import React from 'react'
import { hot } from 'react-hot-loader/root'

export const A = hot(() => <p>a</p>)

Usage

npm install --save-dev @sourcegraph/babel-plugin-transform-react-hot-loader-wrapper
# or
yarn add --dev @sourcegraph/babel-plugin-transform-react-hot-loader-wrapper

Then add this to your Babel configuration file (.babelrc or babel.config.js):

{
  "plugins": [
    [
      "@sourcegraph/babel-plugin-transform-react-hot-loader-wrapper",
      {
        "modulePattern": "src/.*Page\\.tsx$",
        "componentNamePattern": "Page$"
      }
    ]
  ]
}

Configuration

  • modulePattern: A regular expression that matches files to process. You probably only want to wrap your own application's React page components, not node_modules or utility modules. The example above (src/.*Page\\.tsx$) matches all files in src/ ending with Page.tsx.
  • componentNamePattern: A regular expression that matches React component names to process. The example above (Page$) matches all React components whose name ends with Page. This matches export const MyPage = () => <p>hello</p> but does not match export function myOtherFunction() { return 123 }.

Known issues

  • default exports are not supported (export default class Foo ...), only named exports (export class Foo ...).

Build

yarn
yarn build

Test

yarn test

Release

Releases are done automatically in CI when commits are merged into master by analyzing Conventional Commit Messages. After running yarn, commit messages will be linted automatically when committing though a git hook.

babel-plugin-transform-react-hot-loader-wrapper's People

Contributors

felixfbecker avatar gbrik avatar renovate-bot avatar sqs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.