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.
English
PDF
EPUB
MOBI
WEB
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.
English
PDF
EPUB
MOBI
WEB
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.
English
PDF
EPUB
MOBI
WEB
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 Mocha
- 30.2 Jest
- 30.3 Mocking
- 30.4 Removing files from tests
- 30.5 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
Authors have earned$9,894,850writing, 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
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
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
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
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.
Functional Design and Architecture
Alexander GraninSoftware Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Introductory Statistics with Randomization and Simulation
Mine Cetinkaya-Rundel, Christopher Barr, OpenIntro, and David DiezA complete foundation for Statistics, also serving as a foundation for Data Science, that introduces inference using randomization and simulation while covering traditional methods.
Leanpub revenue supports OpenIntro, so we can provide free desk copies to teachers interested in using our books in the classroom.
More resources: openintro.org.
Java OOP Done Right
Alan MellorObject Oriented Programming is still a great way to create clean, maintainable code. But only if you use it right.
This book gives you 25 years of OO best practice, ready to use.
You'll learn to design objects behaviour-first, use TDD to help, then confidently apply Design Patterns, SOLID principles and Refactoring to make clean, crafted code.
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.
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.
Composing Software
Eric ElliottAll software design is composition: the act of breaking complex problems down into smaller problems and composing those solutions. Most developers have a limited understanding of compositional techniques. It's time for that to change.
Top Bundles
- #1
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... - #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
Cisco CCNA 200-301 Complet
4 Books
Ce lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301. - #4
CCDE Practical Studies (All labs)
3 Books
CCDE lab - #5
Modern Management Made Easy
3 Books
Read all three Modern Management Made Easy books. Learn to manage yourself, lead and serve others, and lead the organization. - #6
The Future of Digital Health
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 and how technology giants such as Amazon or Google want to conquer... - #7
Django for Beginners/APIs/Professionals
3 Books
- #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é... - #9
Advanced Product Management
3 Books
Get The Art of Strategy, Product Discovery and Lean Product Management with a 20% discount. - #10
C++17 in Detail and Lambda Story
2 Books
Get all of my books much cheaper! With this package, you'll learn the exciting things available in C++17 and also understand lambda expressions.