Skip to content

This Project helps in understanding how the "create-react-app" works behind the scene. This react boiler plate project is built using webpack, babel and React.

Notifications You must be signed in to change notification settings

Kailashw/webpack-boiler-plate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Name : react-boiler-plate

This Project helps in understanding how the "create-react-app" works behind the scence. This react boiler plate project is built using webpack, babel and React.

Steps to follow to use this boiler-plate.

  1. You can either clone the repo by using command git clone https://github.com/Kailashw/webpack-boiler-plate or simply downloading the zip file from the location.
  2. Go to the location of downloaded file and open command prompt.
  3. Run "npm install"
  4. Followed by "npm launch"

Steps that you should follow to build this boiler plate from scratch.

Open the command prompt and start executing the following commands sequentially.

  1. mkdir webpack-bolier-plate
  2. // this is the folder that we will work on
  3. cd webpack-bolier-plate
  4. npm init -y
  5. // to create a package.json file.
  6. npm install react react-dom
  7. // installing react and react-dom
  8. npm install --save-dev @babel/core @babel/preset-env @babel/preset-react css-loader html-webpack-plugin style-loader webpack webpack-cli webpack-dev-server babel-loader
  9. // installing supporting libraries

Manipulation of Files.

  • now create a file named webpack.config.js

  • The following lines help to bundle all modules in app into single file. so let's define entry point and destination folder/filename.

      module.exports ={
          entry : './app/index.js',
          output : {
              path : path.resolve(__dirname,'dist'),
              filename : 'index_bundle.js'
          }
      }
    
  • the followig lines help us set rules on our js and css files and how to deal with them and should be added after the 'output' entry in previous step.

      module :{
         rules :[
              { test : /\.(js)$/,use : 'babel-loader'},
              { test : /\.(css)$/,use:['style-loader','css-loader']}
          ]
      }
    
  • now add following code, whcih defines which mode you want use your code and to which html page your bundle index_bundle.js file should be exported to. this should be added to module.export object.

      mode : 'development',
      plugins :[
          new HtmlWebpackPlugin({
              template : 'app/index.html'
          })
      ]
    
  • create a new file named .babelrc and have following in that file.

      {
          "presets": [
              "@babel/preset-env",
              "@babel/preset-react"
          ]
      }
    
  • add follolwing inside the "scripts" section, to build and launch the app inside package.json

      "build": "webpack",
      "launch": "webpack-dev-server --open"
    
  • run "npm run build" to see your first build exported to 'dist' folder 😊

  • now run the "npm run launch" command to see the app working.



NOTE: I have followed this youtube video tutorial but added my own customization on top of it.

About

This Project helps in understanding how the "create-react-app" works behind the scene. This react boiler plate project is built using webpack, babel and React.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages