React+webpack Development Environment Construction + Port modification

Source: Internet
Author: User
Tags json require

1). Create a new Mynew-react-web folder;

2). CD mynew-react-web;

3). NPM init, there will be a Package.json file at this time;

Installation package dependencies:
4). NPM Install Webpack webpack-dev-server--save-dev;

5). NPM Install Babel-core Babel-loader--save-dev;

6). NPM Install babel-preset-es2015 babel-preset-react--save-dev;

7). Type NUL>.BABELRC, new. babelrc file;

{
    "presets": ["es2015", "React"]
}

8). NPM Install babel-preset-es2015 babel-preset-react--save-dev;

9). NPM Install Htm-webpack-plugin--save-dev;

9). NPM Install Htm-webpack-plugin--save-dev;

Project directory:

Webpack.config.js File Contents

var path = require (' path ');
var webpack = require (' Webpack ');
var htmlwebpackplugin = require (' Html-webpack-plugin ');

var Root_path = path.resolve (__dirname);
var App_path = path.resolve (Root_path, ' APP ');
var Build_path = path.resolve (Root_path, ' BUILD ');

Module.exports = {
    entry:{
        app:path.resolve (app_path, ' app.jsx ')
    },
    output:{
        Path:build_path ,
        filename: ' Bundle.js '
    },
    devtool: ' Eval-source-map ',
    devserver:{
        historyapifallback: True,
        hot:true,
        inline:true,
        progress:true
    },
    module:{
        loaders:[{
            test:/\. jsx?$/,
            loaders:[' Babel-loader '],
            include:app_path
        }],
    },
    plugins:[
        New Htmlwebpackplugin ({
            title: ' My first react '
        })
}

Package.json File Contents

{
  "name": "Mynew-react-web",
  "version": "1.0.0",
  "description": "",
  "main": "Index.js",
  " Scripts ": {
    " test ":" Echo \ "Error:no test specified\" && exit 1 ",
    " Build ":" Webpack ",
    " dev ":" Webpac K-dev-server--hot "
  },
  " author ":" Lyn ",
  " license ":" ISC ",
  " Devdependencies ": {
    " Babel-core " : "^6.26.0",
    "Babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^ 6.24.1 ",
    " Eslint ":" ^4.17.0 ",
    " Eslint-loader ":" ^1.9.0 ",
    " Html-webpack-plugin ":" ^2.30.1 ",
    " React ":" ^16.2.0 ",
    " React-dom ":" ^16.2.0 ",
    " Webpack ":" ^2.7.0 ",
    " Webpack-dev-server ":" ^2.1.0- beta.10 "
  },
  " dependencies ": {}
}

APP.JSX File Contents

Import React from ' React ';
Import reactdom from ' React-dom ';

Class App extends react.component{
    Constructor (props) {
        super (props);
    }
    Render () {
        return (
            <div>
                

index.html File Contents

<! DOCTYPE html>

At this point: after NPM run dev

Port modified to 8181:
Package.json, change to

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.