React-webpack (i)

Source: Internet
Author: User

To let Webpack know this is our index.html portal file, and we do not need to manually introduce the packaged JS file, need to installhtml-webpack-plugin

NPM Install Html-webpack-plugin--save-dev

Const Htmlwebpackplugin = require (' html-webpack-plugin '= {    plugins: [        New  Htmlwebpackplugin ({            // Specify template path            // specify filename         })    ] }

React inside the JSX grammar ordinary browser can not parse, need to install Babel to parse

NPM Install Babel babel-cli babel-loader--save-dev

Install two more plugins for parsing es6 and JSX syntax, respectively:

NPM Install babel-preset-env babel-preset-react--save-dev

Module.exports = {...  Module: {        // config loader             {                / / Configure the file format to be processed, usually using regular expression matching                // the loader name used                // Babel configuration parameters, can be written in the. babelrc file can also be written here                    Presets: [' env ', ' React '}}                ]}    }

Webpack most important configuration in the modules (module), loaders (loader) is the processing of source files, you will see, loader can handle different JS (JSX, ES6, etc.) compiled into the js,less, etc. compiled into CSS, Process static resource paths such as pictures referenced in your project into paths that can be correctly identified after packaging

Compile the CSS file separately (only in the production environment configuration)

In order to load faster will be the CSS and JS packaged into different files, the use of extract-text-webpack-plugin plug-ins can be separated CSS. In fact, the development of the time is not required to compile a separate CSS file. If you add this in the development environment and configure the hot update, then you will find that the CSS changes when the hot update can not be used, so it is recommended that the development environment do not configure this

NPM Install Extract-text-webpack-plugin--save

Const Extracttextwebpackplugin = require (' Extract-text-webpack-plugin '); Module.exports= {    //...module: {loaders: [{test:/\.css/, Use:ExtractTextWebpackPlugin.extract ({fallback:"Style-loader", use:"Css-loader"})}]}, plugins: [Newhtmlwebpackplugin ({Template:'./public/index.html ', FileName:' Index.html '        }),        NewExtracttextwebpackplugin ("Bundle.css")    ],};

React-webpack (i)

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.