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)