
Understand basics – what Webpack does, how it is installed, how it is used
All manner of practical webpack skills
Installation
Configuration
Using it to compile
Watching files
Much more!
Using Webpack to build an application
Browsers understand plain JavaScript
Not TypeScript
Not JSX
Not React
Webpack turns complex applications into a single file. This file can run in the browser
Understand basics of how and why Webpack is used
Install and configure Webpack
Use Webpack Dev Server to optimize workflow
Master loading ES6, JSX and CSS files with Webpack
Learn to adapt Webpack to different filetypes (example: YAML)
Apply: Create a reasonably sophisticated game that works in the browser but is written using an orderly assortment of files. (example: Hangman)
An entry file is loaded into memory
Any files it requires are loaded in
Code is transformed in format browsers understand
Non code-files, like CSS, can be embedded in code
Loaders are plugins for Webpack that let it interpret specific kinds of files
Without a loader for, e.g, .jsx files, Webpack will throw an error
Babel-loader typically used for .jsx
Loaders for every kind of file available (or can be developed)
Webpack is constantly releasing new versions
Performance
Supporting new techniques / files
Using latest best practices
Webpack 2: Old school, but reliable
Webpack 3: Commonly used but imperfect
Webpack 4: Sophisticated but hard to understand
Webpack 5: Bleeding Edge
Selecting the appropriate Webpack version varies from project to project
If one version was appropriate for every project, we wouldn’t have so many different versions
Webpack 2 or 3 when you inherit a project that already uses it
Webpack 4 when you are starting a new project where reliability and consistency of tools is a priority
Webpack 5 when you are starting a greenfield project and have room for a mistake or two
Webpack bundles code
Input: Varied source files (JSX, TS, CSS, etc)
Output: A single, highly compatible JS file
Webpack can load and transform many different kinds of files
TS, JSX, CSS and various other files via loaders
A wide variety of Webpack versions exist
For most tasks, v3, v4 or v5 are a good choice
You can’t use a library that isn’t installed
Webpack and related libraries installed via NPM
Webpack almost always needs additional libraries to work:
Babel for ES6 or React
TSC for TypeScript,
Etc.
Required packages are recorded in package.json
Once installed, these tools are configured to work together via webpack.config.json
Installing Webpack can be tricky as we must get the correct version
Install as webpack@*, where * is the version you want
Full source: https://github.com/danielstern/webpack-examplar
Install Webpack via npm
Verify selected version
Save to package.json
Create npm script to invoke webpack
Webpack will be accessible via command line
•Configured via webpack.config.json
•Wide variety of options:
•Input files
•Output files
•Libraries to use while transforming code
•Transformation options
•Documentation available at https://webpack.js.org/
•No one regardless of skill level finishes a webpack project without referring to the documentation or Stack Overflow at least once
Input Files
•You write ‘em
•Always committed to Git, etc.
•JSX, CSS, HTML, YAML, PNG – any file type you can think of
•Usually located in
src or app folders
Output Files
•Weback generates ‘em
•Usually not committed
•Outputs as a single JavaScript file – what could be simpler?
•Usually output to bin or dist folders
•Create webpack.config.json
•Add minimal configuration
Mode
Target
Entry
Output
•Create “hello world” application
•A tool commonly used by developers to work on Webpack projects
•Bundles code automatically in response to file changes
•Opens browser automatically
•Refreshes browser automatically when code is changed
•Saves time vs. manual reloading
•Update package.json to include webpack serve
•Run webpack in serve mode
•Verify application opens and reloads automatically
•JSX is powerful language used in conjunction with React
•JSX must be transformed into JavaScript before we can use it in the browser
•Several additional tools needed:
•babel & associated plugins
•Loader for JSX files
What is Babel?
•Configurable tool used to transform one language to another
•Most commonly used to transform ES6 and JSX in ES5
•Can be used without Webpack
•However, lacks the ability to “bundle” files together
•Install dependencies:
•Create “hello JSX” file with minimal React code
•Configure Webpack to use Babel when loading JSX files
•JavaScript code is not the only thing that can be bundled
by Webpack
•Styles (as CSS, LESS, etc.) can all be added to bundle
•css-loader tool and several others are used
•Webpack can embed CSS into the generated output file
•LESS or SASS can be automatically transformed as part of the same step
•Controlled / automatic scoping
•Compile-time error checking
•Automatic browser hot reload
•Update Webpack config with appropriate loader
•Loader and rule to handle .css files
•Import CSS file in our main JSX file
•Write basic CSS and verify that it is working
•.json / .yml / .csv for config
•.png / .jpg / .gif for pictures
•.css / .less / .sass for styles
•Create a YAML file with configuration for our game
•A file container words separated by category, i.e., science, nature
•Install YAML loader with NPM
•Configure Webpack to load YAML with loader
•Import and integrate the file into our application
•We will create the game Hangman for the browser
•Applications view will be handled by React
•Styles written with CSS and loaded with Webpack
•Configuration in YAML or JSON file
In this demo we build a real HTML / React application on top of our Webpack scaffold.
•Webpack bundles input files into a single output file
•Webpack uses loaders to "learn" how to bundle additional files
•Configuration is located in webpack.config.js
•Webpack and plugins installed via NPM
•Webpack is configured via webpack.config.json
•Style loader is used in conjunction with Webpack to load CSS and other styles
•Styles are imported directly into JS files
•Babel is used with Webpack to transform React applications
•Webpack Dev Server is used to automate development of Webpack apps
JavaScript is the only programming language all web browsers natively understand.
But what happens when your application gets too complex to effectively scale and be maintained when it is written as a loosely-connected array of plain JavaScript files?
The solution, of course, is to write your application using more sophisticated tools like TypeScript, React, LESS, JSON, and more. And to bundle all these non-JavaScript files into one clean package that browsers can understand you need a special tool like Webpack.
In this course, we'll learn everything necessary to build a deployment ready application with Webpack. Some of the key skills we'll be covering include:
Installing Webpack using NPM
Differentiating between Webpack versions
Creating a Webpack configuration file and editing it
Serving Webpack applications in a development context using Webpack Dev Server
Compiling React applications to JavaScript
Compiling CSS to JavaScript
Compiling text files (YAML) to JavaScript objects
... much more
We'll be combining all these skills into a single Webpack application which you can build in real time while taking the course. This fun and interactive application will impress your peers and can be used as a base to practice or develop any Webpack skills you wish!
Don't hesitate. Don't even think about it. Sign on up and get ready to use Webpack and kick-start your career in any of the following high-demand fields:
Back-end developer
Full-stack developer
JavaScript developer
Node developer
Dev-ops and CI specialist
“No gains without pains.” - Benjamin Franklin