React Training
  • React JS Library
  • Roadmap
  • Training OutLine
  • React js basics
    • Understanding React JS
    • React JS a framework?
    • Setting Up React
    • Say Hello to React
    • Everything is a Component
    • Create-react-app
  • React Building Blocks
    • JSX and Babel
    • One Way Data Flow
    • Virtual DOM
    • V of MVC
    • React Terminology
    • React Tooling
  • Day 01
    • Day 01 OutLine
    • All About JSX
    • React Tools/ npm & webpack
    • Introduction of Webpack
    • Hello world using webpack
      • Webpack Setting up with React
    • NPM Scripts | Package JSON
      • Package.json file
    • React JS Principles
      • One Way Data Flow
      • V of MVC
      • Virtual DOM
    • Create React App - Part-1
    • Create React App - Part-2
  • Day 02
    • Quick Recap
      • Quiz
    • State & Props
      • State & Props in Depth
      • State Vs Props | Compare
    • React LifeCycle Methods
      • React LifeCycle Methods for V-0.16 x
    • Constructor | Lifecycle
    • Write Flicker App | First App
  • Day 03
    • Quick Recap
    • Life Cycle Flow
      • Birth and Mounting
      • Initlization and Construction
      • Pre Mounting
      • Render Method
      • componentDidMount
    • Type of React Components
      • Examples- Quick Compare
      • Class and Functional components
      • Functional Components
    • YouTube application
      • Component Design
    • All in One LifeCycle
  • Assignment
    • React App development
  • Day 04
    • Quick Recap on Lifecycle
    • Lifecycle deprecated/New Methods
      • New Lifecycle Methods
    • Lets Build App Netflix | Mock
  • Assignment
    • Github battle App | Assignment
  • Day 05
    • Quick Recap : Hooks
    • ES6 Features | Hands-on
      • ES6 Code Examples
    • Next Stop - React Router | SPA
      • Code examples | Router
      • React Router Building Blocks
      • Application using react-router-dom
  • Day 06
    • Router V4 | Quick Recap
    • ES2015 | 16 Quick Recap
    • LifeCycle Methods -Part-1
    • LifeCycle Methods -Part-2
  • Day 07
    • Quick Recap | New Lifecycle
    • Quick Recap | React Routing
    • Context API | React JS
      • component with context APIs
      • Context API | examples
    • App using Hooks/Context APIs
  • Assignment
    • Assignments
  • State Management Day-08
    • Quick Recap
    • Managing React State
      • What is Redux
      • Understanding Redux
      • Hello World "Redux"
  • React Redux Day - 09
    • Redux State Manager
    • Redux Redux Development
    • Simple Application | Redux
  • Redux Live Application Day -10
    • Redux with existing Application
      • Redux with React App
      • Lets Build More Apps
      • Should I use Redux from Dan
    • Quick Look at JS in React
    • Learn By Reading
  • miscellaneous Items - Day 11
    • Hooks useReducer
    • Hooks useContext
    • Hooks useRef
    • Hooks useEffect
    • Hooks useState
    • Lazy Loading and code splitting
    • Styling React Component
  • React Next Step - Day 12
    • Topics
    • Jest and Enjyme Testing
    • Examples: Testing
  • React Native
    • What is React Native
    • Setting up Environment
      • Linux Systems
    • React Native Hello World App
    • React Native Architecture
    • React Native Vs Native
    • Expo Cli or React Native CLI
  • React Native core Fundamental
    • React Native "Hello World"
    • Course OutLine
    • Getting started with Expo App
    • Layout with Flexbox
    • Working with Styles and Events
    • Manging Component State and Props
    • Build Simple Task List Application
  • What to Debug & How to Debug
    • Debug React Native Application
Powered by GitBook
On this page

Was this helpful?

  1. Day 01

Introduction of Webpack

PreviousReact Tools/ npm & webpackNextHello world using webpack

Last updated 5 years ago

Was this helpful?

webpack 4 logo

WHAT IS WEBPACK? [TL;DR]

is a module builder. This is important to understand, as Webpack does not run during your page, it runs during your development.

Webpack is a tool wherein you use a configuration to explain to the builderhow to load specific things. You describe to Webpack how to load *.jsfiles, or how it should look at .scss files, etc. Then, when you run it, it goes into your entry point and walks up and down your program and figures outexactly what it needs, in what order it needs it, and what each piece depends on. It will then create bundles — as few as possible, as optimized as possible, that you include as the scripts in your application.

To understand what this means, let’s take a brief look at the history of JavaScript and why such behavior is ‘necessary’.

Some developers feel using module loaders is unwise, and prefer the old fashioned style of manually doing everything. There is certainly still merit to understanding all of this, and you should not feel compelled to use a module loader — however, there are as many arguments for how module loaders improve the development process. I personally feel it is wise to use them, but you should experiment and find out for yourself what works the best!

HOW IT WAS

Once upon a time, we had very few scripts on a webpage. You would include them with a few simple lines, such as this;

<head>
   <script src="scripts.js" type="text/javascript"></script>
</head>

This was a simpler time, when pages had few or sparse scripts. You could fit everything in a few files, and you could easily load them without conflict.

HOW IT IS NOW

In the last 10 years, the entire scope and spectrum of web development has completely changed. Now we have dozens of scripts, each with a different purpose, each oftentimes created by a different person, each with different requirements.

It’s not uncommon for a modest, or even a small website to need several script libraries. What is more, these libraries oftentimes depend on other libraries — called “dependencies”. Not only do you have to load these scripts, you have to understand what they need to have loaded first!

ASYNCHRONOUS BY DEFAULT

But wait, there’s more! Not only do you have to load everything in the right order, JavaScript tries to load everything at once by default! This adds insult to injury, as it’s not uncommon for scripts to load in a very different order than you declare.

This behavior is called asynchronous — it means that when the executing context (in this case, the web browser) encounters code, it begins to run it, but keeps going before it finishes.

SEND IN THE MODULES

The problems with scripts are so pervasive that the entire development community as a whole set out to solve it; This emerged as a series of standards called modules. The idea behind modules is a standard way to encapsulate scripts in such a way that they can be referred to as a package, and they can be loaded easily, and declared as dependencies of other modules. Ideally, this would allow everything to load where it is needed, to understand what it needs, and to keep the overhead slim.

However, JavaScript is slow to evolve, as any change to the specification and behavior can only be “supported” when web browsers are updated to understand it. This makes it difficult to push things out the door, as the process of getting browsers up to date — a process that can take a very long time, as home users are not apt to update their browsers due to either lacking technical knowledge, or being afraid of breaking something by doing so.

LOADERS TO THE RESCUE!

And so, here we are now; The current solution to the problem is module loaders. A module loader is usually a tool or a script through which a developer passes their JavaScript through — this tool (or script!) is responsible for determining load priority, dependencies, efficiency, paths, etc. It is a worker whose job is to make your scripts run like you expect without worrying about the overhead.

Webpack is a powerful tool to bundle and Compile applications

Reference -

There are many module loaders, but some of the most popular are ,, , , and . This series of tutorials will focus on Webpack because it is the loader of my choice. There are more module loaders that I’ve not listed, as I obviously have not experienced all of them.

Webpack
SystemJS
JSPM
RequireJS
RollUp
https://medium.com/the-self-taught-programmer/what-is-webpack-and-why-should-i-care-part-1-introduction-ca4da7d0d8dc
Webpack