GithubHelp home page GithubHelp logo

jrenelg / simple_webpack_boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pinglinh/simple_webpack_boilerplate

0.0 1.0 0.0 113 KB

🕸📦Ever wondered how you could set up a React project from scratch? This is the repo for you! I have also written up a blog tutorial to follow along.

Home Page: https://medium.freecodecamp.org/part-1-react-app-from-scratch-using-webpack-4-562b1d231e75

HTML 23.08% JavaScript 76.92%

simple_webpack_boilerplate's Introduction

Simple webpack boilerplate

A ready to use simple webpack boilerplate.

Instructions

  1. Clone this repo
  2. Run npm install
  3. Run npm start, localhost:8080 will open up in your default browser

If you prefer to install things yourself you can follow the instructions below

  1. Run npm init and type your answers to the questions or you can run npm init -y to say yes to every question - you will get default settings
  2. Install the following dependencies:
npm i react react-dom -S
  1. Install the following dev dependencies:
npm i babel-core babel-loader babel-preset-env babel-preset-react css-loader html-webpack-plugin style-loader webpack webpack-cli webpack-dev-server -D
  1. Update your scripts to the following:
"start": "webpack-dev-server --mode development --open",
"build": "webpack --mode production"
  1. Create .babelrc file with the following configurations:
{
  "presets": ["env", "react"]
}
  1. Create webpack.config.js file with the following configurations:
const HtmlWebPackPlugin = require("html-webpack-plugin");

const htmlWebpackPlugin = new HtmlWebPackPlugin({
  template: "./src/index.html",
  filename: "./index.html"
});

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.css$/,
        use: [
          {
            loader: "style-loader"
          },
          {
            loader: "css-loader",
            options: {
              modules: true,
              importLoaders: 1,
              localIdentName: "[name]_[local]_[hash:base64]",
              sourceMap: true,
              minimize: true
            }
          }
        ]
      }
    ]
  },
  plugins: [htmlWebpackPlugin]
};
  1. Create src folder with index.js and index.html file.
  2. index.js should have:
import React from "react";
import ReactDOM from "react-dom";

const Index = () => {
  return <div>Hello React!</div>;
};

ReactDOM.render(<Index />, document.getElementById("index"));
  1. index.html should have:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>React and Webpack4</title>
</head>
<body>
  <section id="index"></section>
</body>
</html>
  1. Create .gitignore file and input /node_modules/ and /dist.

simple_webpack_boilerplate's People

Contributors

pinglinh avatar ahmedhaseeb avatar juandc avatar ronihcohen avatar

Watchers

James Cloos 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.