SurviveJS - Webpack 5
SurviveJS - Webpack 5
From apprentice to master
About the Book
"SurviveJS - Webpack 5" has been built around a tutorial during which you develop a complex configuration while covering different facets of webpack. The 34 short chapters and six appendices work as a reference you can use while developing your web applications. The book has been written with webpack 5 in mind.
Even though the book has been designed around webpack, many of the techniques covered go beyond it. You will learn to improve the quality of your code while becoming aware of optimization techniques that help you to deliver more performant web applications.
The book was developed in collaboration with the webpack community, and its structure has evolved accordingly. A third of royalties go to Tobias Koppers, the author of the tool. The writer is a core developer of webpack so by purchasing this book you will support the effort in multiple ways.
The content has been split as below:
- Foreword by Tobias Koppers, the author of webpack
- Preface by Juho Vepsäläinen, the author of the book and a core developer of webpack
- What is Webpack? - Learn what makes webpack tick
- Developing - Set up a development environment on top of webpack
- Styling - Load and manage styles while learning about topics like autoprefixing and eliminating unused CSS
- Loading Assets - Load different asset types and process them
- Building - Write initial build with webpack and learn techniques like bundle and code splitting
- Optimizing - Learn to optimize the build results by minifying, tree shaking, and other techniques
- Output - Understand webpack's output formats, multiple page builds, and module federation
- Techniques - Learn specific techniques related to topics such as testing and consuming packages
- Extending - Extend webpack with loaders and plugins
- Conclusion - Recap core techniques
- Appendices - Learn how webpack compares with other tools, how to set up Hot Module Replacement, troubleshoot webpack
The Leanpub edition comes with a two page PDF cheatsheet that covers the main ideas of webpack in a compact format. It's also available in poster form (single A3, either portrait or landscape). You also get a ~20 page QA PDF where Tobias Koppers, the creator of the tool answers to tough questions.
Packages
The Book
The book in pdf, epub, mobi. The source code is available at https://github.com/survivejs/webpack.
Includes:
Cheatsheet
Cheatsheet covering webpack's core ideas.
QA with Tobias Koppers, the creator of the tool
This brief document (30+) pages contains QA (questions/answers) with Tobias Koppers, the creator of the tool. Read it to gain more insight into webpack and where it's going.
Posters
Posters covering webpack's core ideas. Print in A3 for the best result.
PDF
EPUB
MOBI
WEB
English
One for a friend too
Get a copy for a friend as well. Includes two copies.
Includes:
Cheatsheet
Cheatsheet covering webpack's core ideas.
QA with Tobias Koppers, the creator of the tool
This brief document (30+) pages contains QA (questions/answers) with Tobias Koppers, the creator of the tool. Read it to gain more insight into webpack and where it's going.
Posters
Posters covering webpack's core ideas. Print in A3 for the best result.
PDF
EPUB
MOBI
WEB
English
One for the team
Get copies for your team mates. Or friends. I don't discriminate. Includes four copies.
Includes:
Cheatsheet
Cheatsheet covering webpack's core ideas.
QA with Tobias Koppers, the creator of the tool
This brief document (30+) pages contains QA (questions/answers) with Tobias Koppers, the creator of the tool. Read it to gain more insight into webpack and where it's going.
Posters
Posters covering webpack's core ideas. Print in A3 for the best result.
PDF
EPUB
MOBI
WEB
English
Bundles that include this book
Reader Testimonials

Gavin Doughtie (Senior Software Engineer, Google)
Before I worked through the SurviveJS Webpack book, my own Webpack config, cobbled together from random code on the Internet, was a mystery to me. Afterwards, I have route-splitting and parallel-loading superpowers.

Clément Paris (Front-End Engineer)
After weeks failing at configuring webpack, I stumbled upon SurviveJS book while looking for yet another tutorial. Since that day, it has been my go-to resource for every single webpack question I ever had.

Andrea Chiumenti (CEO, Red Software Systems)
Brilliant! A must have if you want to to learn Webpack but also if need an updated reference guide. I always use it as a reference guide when I develop.

Neeraj Singh (Founder of BigBinary)
Practical tips on Webpack
Webpack is powerful but configuring it can be painful. Same goes with React. There are so many ways of configuring React with asset compilation, minification etc that it is easy to get lost. This book provides practical tips on how to proceed.

Stefan Frede (Developer)
This book is an invaluable resource if you start working with Webpack!

Aaron Harris (Software Engineer)
This guide was a great starter in taming the Wild West of ESNext-era JavaScript development. It's beauty comes from its commitment to not skipping the fundamentals in favor of a fast demo, but making sure you're understanding what you're doing as you bootstrap your next JavaScript-based UI project.

Julien Castelain (Software Engineer, Liferay)
This guide is a great way to get started with webpack or improve your existing skills
After a detailed introduction, you'll start working on a webpack project that provides all you need to push your app to production. Highly recommended.
Table of Contents
-
- Foreword
- Preface
-
Introduction
- What is webpack
- How webpack changes the situation
- What will you learn
- How is the book organized
- Who is the book for
- What are the book conventions
- How is the book versioned
- How to get support
- Where to find additional material
- Acknowledgments
-
What is Webpack
- Webpack relies on modules
- Webpack’s execution process
- Webpack is configuration driven
- Hot Module Replacement
- Asset hashing
- Code splitting
- Webpack 5
- Conclusion
-
I Developing
-
1. Getting Started
- 1.1 Setting up the project
- 1.2 Installing webpack
- 1.3 Running webpack
- 1.4 Setting up assets
- 1.5 Configuring mini-html-webpack-plugin
- 1.6 Examining the output
- 1.7 Adding a build shortcut
- 1.8 Conclusion
-
2. Development Server
-
2.1 Webpack
watch
mode - 2.2 webpack-dev-server
- 2.3 webpack-plugin-serve
- 2.4 Accessing development server from the network
- 2.5 Polling instead of watching files
- 2.6 Making it faster to develop webpack configuration
- 2.7 Development plugins
- 2.8 Watching files outside of webpack’s module graph
- 2.9 Conclusion
-
2.1 Webpack
-
3. Composing Configuration
- 3.1 Possible ways to manage configuration
- 3.2 Composing configuration by merging
- 3.3 Setting up webpack-merge
- 3.4 Benefits of composing configuration
- 3.5 Configuration layouts
- 3.6 Conclusion
-
1. Getting Started
-
II Styling
-
4. Loading Styles
- 4.1 Loading CSS
- 4.2 Setting up initial CSS
- 4.3 PostCSS
- 4.4 Using CSS preprocessors
- 4.5 Understanding css-loader lookups
- 4.6 Conclusion
-
5. Separating CSS
-
5.1 Setting up
MiniCssExtractPlugin
- 5.2 Managing styles outside of JavaScript
- 5.3 Conclusion
-
5.1 Setting up
-
6. Eliminating Unused CSS
- 6.1 Setting up Tailwind
- 6.2 Enabling PurgeCSS
- 6.3 Conclusion
-
7. Autoprefixing
- 7.1 Setting up autoprefixing
- 7.2 Defining a browserslist
- 7.3 Conclusion
-
4. Loading Styles
-
III Loading Assets
-
8. Loader Definitions
- 8.1 Anatomy of a loader
- 8.2 Loader evaluation order
- 8.3 Passing parameters to a loader
- 8.4 Inline definitions
-
8.5 Branching at
use
using a function -
8.6 Loading with
info
object -
8.7 Loading based on
resourceQuery
-
8.8 Loading based on
issuer
- 8.9 Alternate ways to match files
- 8.10 Understanding loader behavior
- 8.11 Conclusion
-
9. Loading Images
- 9.1 Integrating images to the project
-
9.2 Using
srcset
s - 9.3 Optimizing images
- 9.4 Loading SVGs
- 9.5 Loading images dynamically
- 9.6 Loading sprites
- 9.7 Using placeholders
- 9.8 Referencing to images
- 9.9 Conclusion
-
10. Loading Fonts
- 10.1 Setting up a loader
- 10.2 Using icon fonts
- 10.3 Using Google Fonts
-
10.4 Manipulating file-loader output path and
publicPath
- 10.5 Eliminating unused characters
- 10.6 Generating font files based on SVGs
- 10.7 Conclusion
-
11. Loading JavaScript
- 11.1 Using Babel with webpack configuration
- 11.2 Polyfilling features
- 11.3 Babel tips
- 11.4 Babel plugins
- 11.5 Generating differential builds
- 11.6 TypeScript
- 11.7 WebAssembly
- 11.8 Conclusion
-
8. Loader Definitions
-
IV Building
-
12. Source Maps
- 12.1 Inline source maps and separate source maps
- 12.2 Enabling source maps
- 12.3 Source map types supported by webpack
- 12.4 Inline source map types
- 12.5 Separate source map types
- 12.6 Other source map options
-
12.7
SourceMapDevToolPlugin
andEvalSourceMapDevToolPlugin
- 12.8 Changing source map prefix
- 12.9 Extracting source from source maps
- 12.10 Source maps on backend
- 12.11 Ignoring source map related warnings
- 12.12 Using dependency source maps
- 12.13 Conclusion
-
13. Code Splitting
- 13.1 Code splitting formats
- 13.2 Controlling code splitting on runtime
- 13.3 Code splitting in React
- 13.4 Disabling code splitting
- 13.5 Machine learning driven prefetching
- 13.6 Conclusion
-
14. Bundle Splitting
- 14.1 Adding something to split
-
14.2 Setting up a
vendor
bundle - 14.3 Controlling bundle splitting
- 14.4 Splitting and merging chunks
- 14.5 Bundle splitting at entry configuration
- 14.6 Chunk types in webpack
- 14.7 Conclusion
-
15. Tidying Up
- 15.1 Cleaning the build directory
- 15.2 Attaching a revision to the build
- 15.3 Copying files
- 15.4 Conclusion
-
12. Source Maps
-
V Optimizing
-
16. Minifying
- 16.1 Minifying JavaScript
- 16.2 Speeding up JavaScript execution
- 16.3 Minifying HTML
- 16.4 Minifying CSS
- 16.5 Compressing bundles
- 16.6 Obfuscating output
- 16.7 Conclusion
-
17. Tree Shaking
- 17.1 Demonstrating tree shaking
- 17.2 Tree shaking on package level
- 17.3 Tree shaking with external packages
- 17.4 Conclusion
-
18. Environment Variables
-
18.1 The basic idea of
DefinePlugin
-
18.2 Setting
process.env.NODE_ENV
- 18.3 Choosing which module to use
- 18.4 Conclusion
-
18.1 The basic idea of
-
19. Adding Hashes to Filenames
- 19.1 Placeholders
- 19.2 Setting up hashing
- 19.3 Conclusion
-
20. Separating a Runtime
- 20.1 Extracting a runtime
- 20.2 Using records
- 20.3 Integrating with asset pipelines
- 20.4 Conclusion
-
21. Build Analysis
- 21.1 Configuring webpack
- 21.2 Enabling a performance budget
- 21.3 Dependency analysis
- 21.4 Composition analysis
- 21.5 Output plugins
- 21.6 Online services
- 21.7 Bundle comparison
- 21.8 Unused files analysis
- 21.9 Duplication analysis
- 21.10 Understanding why a module was bundled
- 21.11 Conclusion
-
22. Performance
- 22.1 Measuring impact
- 22.2 High-level optimizations
- 22.3 Low-level optimizations
- 22.4 Optimizing rebundling speed during development
- 22.5 Webpack 4 performance tricks
- 22.6 Conclusion
-
16. Minifying
-
VI Output
-
23. Build Targets
- 23.1 Web targets
- 23.2 Node targets
- 23.3 Desktop targets
- 23.4 Conclusion
-
24. Multiple Pages
- 24.1 Possible approaches
- 24.2 Generating multiple pages
- 24.3 Progressive web applications
- 24.4 Conclusion
-
25. Server-Side Rendering
- 25.1 Setting up Babel with React
- 25.2 Setting up a React demo
- 25.3 Configuring webpack
- 25.4 Setting up a server
- 25.5 Open questions
- 25.6 Prerendering
- 25.7 Conclusion
-
26. Module Federation
- 26.1 Module federation example
- 26.2 Adding webpack configuration
- 26.3 Implementing the application with React
- 26.4 Separating bootstrap
- 26.5 Separating header
- 26.6 Pros and cons
- 26.7 Learn more
- 26.8 Conclusion
-
23. Build Targets
-
VII Techniques
-
27. Dynamic Loading
-
27.1 Dynamic loading with
require.context
-
27.2 Dynamic paths with a dynamic
import
-
27.3 Combining multiple
require.context
s - 27.4 Dealing with dynamic paths
- 27.5 Conclusion
-
27.1 Dynamic loading with
-
28. Web Workers
- 28.1 Setting up a worker
- 28.2 Setting up a host
- 28.3 Sharing data
- 28.4 Other options
- 28.5 Conclusion
-
29. Internationalization
- 29.1 i18n with webpack
- 29.2 Setting up translations
- 29.3 Setting up webpack
- 29.4 Setting up application
- 29.5 Conclusion
-
30. Testing
- 30.1 Jest
- 30.2 Mocking
- 30.3 Removing files from tests
- 30.4 Conclusion
-
31. Deploying Applications
- 31.1 Deploying with gh-pages
- 31.2 Deploying to other environments
-
31.3 Resolving
output.publicPath
dynamically - 31.4 Conclusion
-
32. Consuming Packages
-
32.1
resolve.alias
-
32.2
resolve.modules
-
32.3
resolve.extensions
-
32.4
resolve.plugins
- 32.5 Consuming packages outside of webpack
- 32.6 Dealing with globals
- 32.7 Managing symbolic links
- 32.8 Removing unused modules
- 32.9 Managing pre-built dependencies
- 32.10 Getting insights on packages
- 32.11 Conclusion
-
32.1
-
27. Dynamic Loading
-
VIII Extending
-
33. Extending with Loaders
- 33.1 Debugging loaders with loader-runner
- 33.2 Implementing an asynchronous loader
- 33.3 Returning only output
- 33.4 Writing files
- 33.5 Passing options to loaders
- 33.6 Connecting custom loaders with webpack
- 33.7 Pitch loaders
- 33.8 Caching with loaders
- 33.9 Conclusion
-
34. Extending with Plugins
- 34.1 The basic flow of webpack plugins
- 34.2 Setting up a development environment
- 34.3 Implementing a basic plugin
- 34.4 Capturing options
- 34.5 Understanding compiler and compilation
- 34.6 Writing files through compilation
- 34.7 Managing warnings and errors
- 34.8 Plugins can have plugins
- 34.9 Conclusion
-
33. Extending with Loaders
-
Conclusion
-
- General checklist
- Development checklist
- Production checklist
- Conclusion
-
-
Appendices
-
Comparison of Build Tools
- Task runners
- Script loaders
- Bundlers
- Zero configuration bundlers
- Other Options
- Conclusion
-
Hot Module Replacement
- Enabling HMR
- Implementing the HMR interface
- Setting WDS entry points manually
- HMR and dynamic loading
- Conclusion
-
CSS Modules
- CSS Modules through css-loader
- Using CSS Modules with third-party libraries and CSS
- Conclusion
-
Searching with React
- Implementing search with code splitting
- Conclusion
-
Troubleshooting
- Module related errors
- DeprecationWarning
- Conclusion
- Glossary
-
Comparison of Build Tools
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Do Well. Do Good.
Authors have earned$11,586,736writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
SignalR on .NET 6 - the Complete Guide
Fiodar SazanavetsLearn everything there is to learn about SignalR and how to integrate it with the latest .NET 6 and C# 10 features. Learn how to connect any type of client to SignalR, including plain WebSocket client. Learn how to build interactive applications that can communicate with each other in real time without making excessive calls.
The easiest way to learn design patterns
Fiodar SazanavetsLearn design patterns in the easiest way possible. You will no longer have to brute-force your way through each one of them while trying to figure out how it works. The book provides a unique methodology that will make your understanding of design patterns stick. It can also be used as a reference book where you can find design patterns in seconds.
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
Functional event-driven architecture: Powered by Scala 3
Gabriel VolpeExplore the event-driven architecture (EDA) in a purely functional way, mainly powered by Fs2 streams in Scala 3!
Leverage your functional programming skills by designing and writing stateless microservices that scale, powered by stateful message brokers.
Tech Giants in Healthcare
Dr. Bertalan MeskoThis comprehensive guide, Tech Giants in Healthcare, clarifies how and why big tech companies step into healthcare, and breaks it down from one market player to the other in what direction they are going, what tools they are using and what horizons they have in front of them.
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
C++20 - The Complete Guide
Nicolai M. JosuttisAll the new language and library features of C++20 (for those who know previous versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
CCIE Service Provider Version 4 Written and Lab Exam Comprehensive Guide
Nicholas RussoThe service provider landscape has changed rapidly over the past several years. Networking vendors are continuing to propose new standards, techniques, and procedures for overcoming new challenges while concurrently reducing costs and delivering new services. Cisco has recently updated the CCIE Service Provider track to reflect these changes; this book represents the author's personal journey in achieving that certification.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Top Bundles
- #1
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #2
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #3
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #4
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #6
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #7
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also... - #8
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #10
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity...