Webpack+react Development Environment Construction

Source: Internet
Author: User

I. Installing node. js

node. JS can be downloaded directly from the official website and installed in the default installation mode.

Second, installation Webpack

Webpack can install with NPM, create a new empty Practice folder, and execute the following instructions after the terminal is transferred to the folder to complete the installation.

// Global Installation NPM install-g webpack// install to your project directory npm install--save-dev webpack
Third, installation Webpack-dev-server
// Global Install npm install-g webpack-dev-server// install to your project directory npm install--save-dev Webpack-dev-server

Iv. Generating Package.json files
// generate the initial Package.json file npm init-y

Create a new two folder in the project folder:app and build, each with main.js and index.html

// Package.json {  "name": "Tic-Tac-Toe",  "version": "1.0.0",  "description": "",  "main": "Index.js",  "Scripts": {    "test": "Echo \" Error:no Test specified\ "& & Exit 1 ",    " build ":" Webpack ",// to point the build command of NPM to the Webpack command    " Start ":" Webpack-dev-server--inline--hot "  },  " keywords ": [],  " author ":",   "license": "ISC"}

// index.html<! DOCTYPE html>src= "http://localhost:8080/ Bundle.js "></script>//Note src Properties </body>

v. New Webpack.config.js file

Create a new Webpack.config.js file under the project directory with the following contents:

Module.exports = {  entry:  + "/app/main.js",// The only entry file output that has been mentioned several times   : {     + "/build",// The place where the files are packed after filename    : "bundle.js"// file name of the output file after packaging  }}
Liu, loaders1.JSON

// installs the loader NPM install--save-dev Json-loader that can be loaded with JSON
2.Babel
// NPM installs multiple dependent modules at once, separating the modules with a space between npm install--save-dev babel-core babel-loader babel-preset-es2015 Babel-preset-react

3.react
NPM Install--save react react-dom

4.css
// installing npm install--save-dev style-loader css-loader

The final webpack.config.js file:

//Webpack.config.jsModule.exports={devtool:' Eval-source-map ', entry: __dirname+ "/app/main.js", Output: {path: __dirname+ "/build", FileName:"Bundle.js"}, module: {loaders: [{test:/\.json$/, Loader:"Json-loader"}, {test:/\.jsx?$/, exclude:/node_modules/, Loader:' Babel-loader ', query: {presets: [' es2015 ', ' react ']}}, {test:/\.css$/, Loader:' Style-loader!css-loader '//add a handle to a style sheet}]}, Devserver: {...}}
Vii. the difference between the problems encountered 1.--save-dev and--save

--save-dev is only used in the development of the dependency,-save is the project on-line also need to use the dependency.

Webpack+react Development Environment Construction

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.