React-hot-loader Records

Source: Internet
Author: User
Tags require

1.

NPM Install--save-dev babel-core babel-loader babel-preset-es2015 babel-preset-react babel-preset-stage-2

2.

NPM Install--save-dev react-hot-loader@3.0.0-beta.6
or
npm install--save-dev react-hot-loader@next

3.

. BABELRC configuration


{
  "presets": [
    ["es2015", {"modules": false}],
       //Webpack now supports native import statements, and use it in the tree-shaking characteristics
    of the "stage-2",
      //Set the language standard JS application level
      //Stage 2 is "Draft", 4 is "completed", 0 is "Scarecrow (strawman)".
      //Details View https://tc39.github.io/process-document/
    "react"
      //Translator react Component JS code
  ],
  "plugins": [
    "React-hot-loader/babel"
      //Open module hot swap for react code (HMR)
  ]
}

4.

Config configuration:


const {Resolve} = require (' path ');
Const WEBPACK = require (' Webpack ');
Module.exports = {
  context: __dirname,
  entry:  [
    ' React-hot-loader/patch ',
    ' webpack/hot/ Only-dev-server ',
    './app/main.js '
  ],
  output: {
    path:resolve (__dirname, ' build '),//Where the packaged file is stored
    filename: "Bundle.js",//after packaging the file name
    Publicpath: "/"
  },
  devserver: {
    contentbase:resolve (__dirname, ' build '),
    hot:true,
    publicpath: '/'
  },
  module: {
    rules: [
      {
        test:/\ . jsx?$/, use
        : [
          ' Babel-loader ',
        ],
        exclude:/node_modules/
      },
    ],
  },
  Plugins: [
    new Webpack. Hotmodulereplacementplugin (),
    new Webpack. Namedmodulesplugin (),
  ],
  devtool: "Cheap-eval-source-map",
};

5.

 ingress file configuration: import {Appcontainer} from ' React-hot-loader ' import Redbox from ' redbox-react ' const Render = (Component) = {Reactdom.render (<appcontainer errorreporter={redbox}> <component/>
    ;
</appcontainer>, Document.queryselector (' #odiv ')};

Render (APP);

if (module.hot) {module.hot.accept ('./app ', () = {render (APP)});}
or const Oele = document.queryselector (' #odiv ');  Render (<appcontainer errorreporter={redbox}> <app/> </appcontainer>, Oele) if (module.hot)
    {module.hot.accept ('./app ', () = = {Const NEXTAPP = require ('./app '). Default; Render (<appcontainer errorreporter={redbox}> <nextapp/> </appcontainer>, oEl
e)}); }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.