react-webpack--development of a React project required preparation

Source: Internet
Author: User
NPM init-generate a Package.json file

Install dependent NPM install–save react npm install–save react-dom npm install–save-dev webpack npm install–save-dev webpack-dev-s erver npm install–save-dev babel-core npm install–save babel-polyfill npm install–save-dev babel-loader npm Install–sa Ve-dev style-loader css-loader npm install–save-dev file-loader npm install–save babel-runtime npm Install–save-dev Bab El-plugin-transform-runtime npm install–save-dev babel-preset-es2015 npm install–save-dev babel-preset-react NPM Install–save-dev babel-preset-stage-2 npm install–save webpack-cli ' npm Install–save-dev node-sass//can not be added, corresponding to the following configuration in the section about sass to delete npm Install–save-dev sass-loader//can not add NPM install Redux React-redux//Do not know redux can not add

Open Package.json and add the following scripts:

"Scripts": {
"Start": "Webpack-dev-server–hot–inline–colors–content-base./build",
"Build": "Webpack–progress–colors"
}

Configuring the Webpack.config.js File

Create a new Webpack.config.js file under the root directory and enter the following:

'
var webpack = require (' Webpack ');
Module.exports = {
 entry: './src/app/index.js ',
 output: {
     path: __dirname + '/build ',
     filename: " Bundle.js "
 },
 module: {
     rules: [{
         test:/\.js$/,
         exclude:/node_modules/,
         loader: ' Babel-loader ',
         query: {
             plugins: [' transform-runtime '],
             presets: [' es2015 ', ' react ', ' stage-2 ']
         }
     }, 

     {
         test:/\.css$/,
         use:[' Style-loader ', ' Css-loader ']
     },

     {
        test:/\. scss$/, use
        : [
            ' Css-loader ',
            ' Sass-loader '
    }},
    {
        test:/\. ( PNG|SVG|JPG|GIF|MP4) $/, use
        : [' File-loader '
    }]
    }
};
```

Basic configuration complete next look at the directory
After writing the code run npm start can run up just contact react friends can go to crossing Web tutorial, two code on a scaffold, do not need to match. Very friendly to beginners. –> Portal <–

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.