Code Monkey home page Code Monkey logo

Comments (9)

MeetzhDing avatar MeetzhDing commented on July 28, 2024 11

@GloriaCHL @alexkreidler

I get this solution, and it's work for me !

const { override, fixBabelImports } = require('customize-cra');
const rewireReactHotLoader = require('react-app-rewire-hot-loader');

module.exports = override(
  fixBabelImports('import', {
    libraryName: 'antd',
    libraryDirectory: 'es',
    style: 'css',
  }),
  (config, env) => {
    config = rewireReactHotLoader(config, env);
    return config;
  }
)

Other steps: http://npm.taobao.org/package/react-app-rewire-hot-loader

from customize-cra.

quannh25595 avatar quannh25595 commented on July 28, 2024 5

I don't know why but the env in @MeetzhDing seems to be undefined. And I found mode inside config. This code works for me:

const { override, fixBabelImports } = require('customize-cra');
const rewireReactHotLoader = require('react-app-rewire-hot-loader');

/* config-overrides.js */
module.exports = override(
  fixBabelImports('import', {
    libraryName: 'antd',
    libraryDirectory: 'es',
    style: 'css',
  }),
  config => {
    if (config.mode === 'development') {
      config.resolve.alias['react-dom'] = '@hot-loader/react-dom';
    }
    config = rewireReactHotLoader(config, config.mode);
    return config;
  },
);

from customize-cra.

FezVrasta avatar FezVrasta commented on July 28, 2024 1

You may try to use the addBabelPlugin utility to add react-hot-loader/babel and see if it works.

from customize-cra.

SteffeyDev avatar SteffeyDev commented on July 28, 2024 1

I got it working just by putting the function in directly:

const rewireReactHotLoader = require('react-app-rewire-hot-loader');

module.exports = override(
  rewireReactHotLoader,
  ...otherOptions
}

Conceptually, this is equivalent to @MeetzhDing's solution, just simplified to it's fullest extent.

from customize-cra.

FezVrasta avatar FezVrasta commented on July 28, 2024

Alternatively, if you use Yarn, you may use react-🔥-dom without having to override any CRA config.

yarn add react-dom@npm:@hot-loader/react-dom

from customize-cra.

FezVrasta avatar FezVrasta commented on July 28, 2024

@GloriaCHL have you sorted out your problem? Can we close this issue?

from customize-cra.

alexkreidler avatar alexkreidler commented on July 28, 2024

any updates?

from customize-cra.

SylvanasGone avatar SylvanasGone commented on July 28, 2024

I implemented a plugin which will let you use hot-loader directly without extra code

const { override } = require('customize-cra')
const rewireReactHotLoader = require('react-app-rewire-hot-loader-for-customize-cra')

module.exports = override(
  // ...other rewires
  rewireReactHotLoader()
)

https://www.npmjs.com/package/react-app-rewire-hot-loader-for-customize-cra

have a try

from customize-cra.

liuxinqiong avatar liuxinqiong commented on July 28, 2024

@quannh25595 It worked for me,thanks for your share

from customize-cra.

Related Issues (20)

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.