Webpack + Babel: Introduction and Detailed Examples

姜瑞涛Publishing House of Electronics Industry · ChinaJul 2022

Rating 3.3
Word count
83K words
Chapters
79
ISBN
9787121424724

Tags

Programming Code TranspilationFront-End ToolsDev EnvironmentBuild ToolsStep-by-Step GuideExample TeachingPractical GuideSelf-Study GuideBeginner FriendlyProgramming Primer

Summary

This book teaches Webpack and Babel from scratch for frontend developers with no prior experience. As frontend engineering has evolved, Webpack and Babel have become two core tools of frontend development. Webpack is currently the mainstream build tool for frontend development, and Babel is the general solution for transpiling ES6 code. The book consists of two parts: Part One covers Webpack, and Part Two covers Babel.

The Webpack part explains Webpack installation, resource entry and output, preprocessor and plugin configuration, development and production environment configuration, performance optimization, and build principles. The Babel part explains Babel fundamentals, Babel configuration files, choosing presets and plugins, how to use babel-polyfill, and how to use the two core configuration items @babel/preset-env and @babel/plugin-transform-runtime. This part also explains how Babel works and how to develop Babel plugins. Finally, the appendix introduces Module Federation and micro-frontends, along with a look ahead to Babel 8.

Editor's review

This book systematically explains Webpack and Babel, the two core tools of frontend engineering, for beginners. The structure is clear: build first, then transpile, matching the toolchain order encountered in real development. The Webpack part starts with installation, entry and output, and preprocessor and plugin configuration, then extends to development and production environment configuration, performance optimization, and build principles, helping readers build a complete path from getting it working to understanding the principles. The Babel part covers fundamentals, configuration files, choosing presets and plugins, babel-polyfill, and the two core configuration items @babel/preset-env and @babel/plugin-transform-runtime, and further explains how Babel works and how to develop plugins, which is very helpful for understanding ES6 code transpilation. The appendix covers Module Federation, micro-frontends, and a look ahead to Babel 8, appropriately broadening the engineering perspective. Overall, the book features detailed examples and is suited to learning by doing, especially for readers new to frontend engineering who need to connect configuration items with real projects. It is best read alongside hands-on work building sample projects, adjusting configurations while reading.

Who it's for

A good fit for

Not a good fit for

Reading tips

  1. First read through the Webpack part and build sample projects by hand, verifying entry, output, and plugin configuration item by item.
  2. When studying the Babel part, follow along with configuration files in practice, focusing on the logic of choosing presets and plugins.
  3. Slow down when reading the chapters on build principles and plugin development, and debug repeatedly with the sample code.
  4. The appendix content on micro-frontends and Babel 8 can be read as further exploration; there is no need to dig into it from the start.

About the publisher

Publishing House of Electronics Industry China · Founded in 1982

The Publishing House of Electronics Industry is a comprehensive publisher distinguished by its focus on electronic information and related fields. Judging from the more than 3,000 titles in its catalogue, its publishing covers programming and design, artificial intelligence, computer science, finance and economics, photography, and social sciences, attending both to cutting-edge technology and to general readers. Representative titles include Factor Investing: Methods and Practice, x86 Assembly Language: From Real Mode to Protected Mode, The RISC-V Reader, Artificial Intelligence: Speech Recognition, Understanding and Practice, Phased Array Radar Technology, Radar Target Characteristics, and 100 Go Mistakes and How to Avoid Them, most of which centre on technical methods and engineering practice. Its authors include Shi Chuan, Li Zhong, Wang Xiaobo, David Patterson, Andrew Waterman, and Yu Zihao, among others from China and abroad. Owing to limited public information, no further publishing features are elaborated here.

Contents

  1. 版权信息
  2. 作者简介
  3. 内容简介
  4. 前言
  5. 读者服务
  6. 第1章 Webpack入门
  7. 1.1 Webpack简介
  8. 1.2 安装Webpack 5
  9. 1.3 Webpack快速入门
  10. 1.4 Webpack预处理器
  11. 1.5 本章小结
  12. 第2章 Webpack资源入口与出口
  13. 2.1 模块化
  14. 2.2 Webpack资源入口
  15. 2.3 Webpack资源出口
  16. 2.4 hash、fullhash、chunkhash和contenthash的区别
  17. 2.5 本章小结
  18. 第3章 Webpack预处理器
  19. 3.1 预处理器的配置与使用
  20. 3.2 Babel预处理器babel-loader
  21. 3.3 文件资源预处理器file-loader
  22. 3.4 增强版文件资源预处理器url-loader
  23. 3.5 本章小结
  24. 第4章 Webpack插件
  25. 4.1 揑件简介
  26. 4.2 清除文件揑件clean-webpack-plugin
  27. 4.3 复制文件揑件copy-webpack-plugin
  28. 4.4 HTML模板揑件html-webpack-plugin
  29. 4.5 本章小结
  30. 第5章 Webpack开发环境配置
  31. 5.1 文件监听与webpack-dev-server
  32. 5.2 模块热替换
  33. 5.3 Webpack中的source map
  34. 5.4 Asset Modules
  35. 5.5 本章小结
  36. 第6章 Webpack生产环境配置
  37. 6.1 环境变量
  38. 6.2 样式处理
  39. 6.3 合并配置webpack-merge
  40. 6.4 性能提示
  41. 6.5 本章小结
  42. 第7章 Webpack性能优化
  43. 7.1 打包体积分析工具webpack-bundle-analyzer
  44. 7.2 打包速度分析工具speed-measure-webpack-plugin
  45. 7.3 资源压缩
  46. 7.4 缩小查找范围
  47. 7.5 代码分割optimization.splitChunks
  48. 7.6 摇树优化Tree Shaking
  49. 7.7 使用缓存
  50. 7.8 本章小结
  51. 第8章 Webpack原理与拓展
  52. 8.1 Webpack构建原理
  53. 8.2 Webpack预处理器开发
  54. 8.3 Webpack揑件开发
  55. 8.4 本章小结
  56. 第9章 Babel入门
  57. 9.1 Babel简介
  58. 9.2 Babel快速入门
  59. 9.3 引入polyfill
  60. 9.4 本章小结
  61. 第10章 深入Babel
  62. 10.1 Babel版本
  63. 10.2 Babel配置文件
  64. 10.3 预设与揑件的选择
  65. 10.4 babel-polyfill
  66. 10.5 @babel/preset-env
  67. 10.6 @babel/plugin-transform-runtime
  68. 10.7 本章小结
  69. 第11章 Babel工具
  70. 11.1 @babel/core
  71. 11.2 @babel/cli
  72. 11.3 @babel/node
  73. 11.4 本章小结
  74. 第12章 Babel原理与Babel插件开发
  75. 12.1 Babel原理
  76. 12.2 Babel揑件开发
  77. 12.3 本章小结
  78. 附录A Module Federation与微前端
  79. 附录B Babel 8前瞻

FAQ

Will this book be too difficult for a complete beginner? The book is aimed at frontend developers with no prior experience, and it starts from installation and basic configuration, progressing step by step. However, readers should ideally have a foundation in HTML, CSS, and JavaScript; otherwise, understanding modularization and ES6 syntax will be difficult. It is recommended to first master basic syntax, then practice with the book's examples.
How much of the book covers Webpack versus Babel? The book consists of two parts. Part One covers Webpack, including installation, entry and output, preprocessors and plugins, development and production environment configuration, performance optimization, and build principles. Part Two covers Babel, including fundamentals, configuration files, choosing presets and plugins, using polyfill, core configuration items, and plugin development. The two parts are relatively independent and can be read as needed.
Do I need to learn the micro-frontend content in the appendix first? The appendix introduces Module Federation, micro-frontends, and a look ahead to Babel 8; this is extension material. It is recommended to read it after mastering the main Webpack content, as it will then be easier to understand where module federation fits in engineering. It does not need to be an entry point.

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

About the author

姜瑞涛 Author

Jiang Ruitao is an author of Chinese programming books. Public information about him is limited: the library records show only one work, Webpack+Babel: A Beginner's Guide with Examples, generally classified under programming and design. The book focuses on Webpack, a widely used build tool in front-end engineering, and Babel, a JavaScript compiler, and is aimed at readers who want a systematic understanding of how these tools are used and configured. It is a technical tutorial that combines introductory explanations with practical examples. The choice of topic suggests that the author attends to the hands-on side of modern front-end development and prefers to organize content around tool basics and worked examples, helping readers grasp build and transpilation workflows. Because little personal background is available, his style and influence are best seen in this book's practical value for learners of front-end tooling, and it can serve as a reference for those beginning with the relevant technologies.