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
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
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
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 Watching files outside of webpack’s module graph
- 2.8 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
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,307,240writing, publishing and selling on Leanpub.
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) and EPUB (for phones, tablets and 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
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.
Personal Finance
Jason AndersonThis textbook provides an in-depth analysis on personal finance that is both practical and straightforward in its approach. It has been written in such a way that the readers can gain knowledge without getting overwhelmed by the technical terms. Suitable for both beginners and advanced learners.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ 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:
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.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Stats One
William FooteThe Rails 7 Way
Obie Fernandez, Lucas Dohmen, and Tom Henrik AadlandThe Rails™ 7 Way is the comprehensive, authoritative reference guide for professionals delivering production-quality code using modern Ruby on Rails. It illuminates the entire Rails 7 API, its most powerful idioms, design approaches, and libraries. Building on the previous editions, this edition has been heavily refactored and updated.
Machine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Gradual Modularization for Ruby and Rails
Stephan HagemannGet yourself a new tool to manage your Rails application and your growing engineering organization! Prevent the ball-of-mud (and fix it!). Go for microservices or SOA if it makes sense not just because you don't have any other tool. Do all this through a low-overhead tool: packages. Enable better conversations to make practical changes today.
Top Bundles
- #1
Software Architecture
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... - #2
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... - #3
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #4
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... - #5
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!? - #6
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... - #7
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é... - #9
Development and Deployment of Multiplayer Online Games, Part ARCH. Architecture (Vol. I-III)
3 Books
What's the Big Idea? The idea behind this book is to summarize the body of knowledge that already exists on multiplayer games but is not available in one single place.And quite a fewof the issues discussed within this series (planned as three nine volumes ~300 pages each), while known in the industry, have not been published at all (except for... - #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...