Giter Site home page Giter Site logo

unam3 / react-webpack-tutorial Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jansoren/react-webpack-tutorial

0.0 2.0 0.0 37 KB

This is a tutorial on how to get started developing a client side application using ReactJS, Webpack and Npm

Home Page: http://jansoren.github.io/react-webpack-tutorial/

JavaScript 100.00%

react-webpack-tutorial's Introduction

React Webpack Tutorial

This tutorial will cover how to get started developing a client side application using these technologies:

You can either follow the tutorial below or just jump to the resulting code with:

  1. Cloning this repo git clone [email protected]:jansoren/react-webpack-tutorial.git
  2. Run npm install from the myapp-folder
  3. Run command webpack
  4. Open /myapp/dist/index.html

If you find the tutorial helpful, and maybe learned something new, please give it a star here. If you have improvement suggestions please create an issue or a pull request. Enjoy :-)

Tutorial prerequisites

  • Use your preferred IDE or you can install Atom
  • Install NodeJS
  • Install Webpack - npm install -g webpack

1. Initializing your project with npm

  1. Enter your project main folder. For this tutorial I will use myapp as folder and you will find the resulting code there
  2. Run npm init to create the project package.json file
  3. Press on the npm init questions to get the default value
  4. Install Webpack with npm install --save-dev webpack. When npm uses --save-dev it automatically adds the webpack package to the package.json

You have now created an initial package.json file that we later on will fill with the necessary packages for installing the application with npm install.

2. Create initial application files

  1. Open myapp-folder in your preferred IDE or Atom
  2. Create your application Webpack config file webpack.config.js in main project folder with this initial content:
var config = {
  context: __dirname + "/app",
  entry: "./main.js",

  output: {
    filename: "bundle.js",
    path: __dirname + "/dist",
  },
};
module.exports = config;
  1. Create folder myapp/app to contain all your application files.
  2. Create your application main file main.js with this initial content:
var React = require('react');
var ReactDOM = require('react-dom');

var Content = React.createClass({
  render: function() {
    return (
      <div>
        <b>Congratulations</b>, you are now ready to implement your client side application! Enjoy :-)
      </div>
    );
  }
});
ReactDOM.render(<Content />, document.getElementById('content'));
  1. Install React DOM and add it to your package.json file automatically using npm install --save react react-dom
  2. Install Babel to transform the content of a .js file from ES6 to ES5 npm install --save-dev babel-preset-react babel-preset-es2015 babel-core babel-loader
  3. In your webpack.config.js add the babel-loader that you just installed like this:
var config = {
  ...
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015']
        }
      }
    ],
  },
};
  1. Create folder myapp/dist and create index.html file with content:
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello React Webpack Tutorial!</title>
  </head>
  <body>
    <div id="content"></div>
    <script src="bundle.js"></script>
  </body>
</html>
  1. Run command webpack in your main folder that will result in something like this:
Hash: dd141258ef660950584c
Version: webpack 1.12.11
Time: 3711ms
  Asset    Size  Chunks             Chunk Names
bundle.js  676 kB       0  [emitted]  main
  + 159 hidden modules
  1. Open /dist/index.html to see your client side application

  2. If you want some pointers on developing your client side application you should check these sites out:

react-webpack-tutorial's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.