| Start |
|---|
Simple setup Setting up the foldersThis example assumes code to be in Setting up the packagesAssuming a setup npm environment, we first need to setup babel in order to transpile the React code into es5 compliant code.
The above command will instruct npm to install the core babel libraries as well as the loader module for use with webpack. We also install the es6 and react presets for babel to understand JSX and es6 module code. (More information about the presets can be found here Babel presets (opens new window))
This command will install webpack as a development dependency. (i is the shorthand for install and -D the shorthand for --save-dev) You might also want to install any additional webpack packages (such as additional loaders or the webpack-dev-server extension) Lastly we will need the actual react code
Setting up webpackWith the dependencies setup we will need a webpack.config.js file to tell webpack what to do simple webpack.config.js: This file tells webpack to start with the index.js file (assumed to be in src/ )
and convert it into a single bundle.js file in the The Testing the setupAll that is left now is to create the src/index.js: This file would normally render a simple
This should create the file |
Using webpack-dev-server SetupAfter setting up a simple project to use webpack, babel and react issuing Modifying webpack.config.jsThe modifications are in
And finally we just need a simple index.html to test our app in. index.html: With this setup running |
Read Article
https://develop.horje.com/learn/1434/reference