From Gulp to Webpack – Evolving Build Tools
October 15, 2016
Many projects that started with Grunt or Gulp switched to Webpack by late 2016 to get built‑in module bundling, dev server live reload, and smarter code splitting.
Two mental models
Gulp / Grunt
- You write JavaScript tasks (
gulp.task('sass', …)
) that pipe files through a series of plugins. - Output goes to
dist/
, then you include built assets with<script>
tags. - Responsibility for dependency graph and live reload belongs to plugins (
gulp‑watch
,browser‑sync
).
Webpack
- You describe what the final bundles should look like (
entry
,output
) and let Webpack walk the dependency graph. - Transforms happen through loaders (e.g.
babel-loader
). webpack-dev-server
serves bundles from memory and applies Hot Module Replacement automatically.
Both tools use Node streams, but Gulp focuses on file pipelines, while Webpack focuses on module graphs. citeturn0search0turn0search4
Quick migration cheat sheet
| Need | Gulp/Grunt plugin | Webpack recipe |
| --- | --- | --- |
| ES6 → ES5 | gulp-babel
| babel-loader
+ .babelrc
|
| Sass → CSS | gulp-sass
| sass-loader
+ MiniCssExtractPlugin
|
| Minify JS | gulp-uglify
| TerserPlugin
(built‑in in prod mode) |
| Live reload | browser-sync
/ gulp-livereload
| webpack-dev-server --hot
|
| Cache‑bust file names | gulp-rev
| [contenthash]
in output.filename
|
(WebPack cheat sheet adapted from Devhints) citeturn0search6
Minimal Webpack setup
npm init -y
# Core
npm install --save-dev webpack@1 webpack-cli@1 webpack-dev-server@1
# Transpile ES6
npm install --save-dev babel-core babel-loader babel-preset-es2015
Create webpack.config.js
module.exports = {
entry: './src/index.js',
output: { filename: 'bundle.[hash].js', path: __dirname + '/dist' },
module: {
loaders: [{ test: /\.js$/, loader: 'babel', exclude: /node_modules/ }]
},
devServer: { hot: true, inline: true }
};
Start in dev mode:
webpack-dev-server --hot --open
Common tasks rewritten
Transpile & bundle JS
# Gulp
gulp babel
# Webpack – just run build, loader handles Babel
webpack --mode production
Auto‑reload on file save
# Gulp + BrowserSync
browser-sync reload
# Webpack dev server
webpack-dev-server --hot
Minify for production
# Gulp
gulp-uglify
# Webpack prod mode enables TerserPlugin automatically
webpack --mode production
Tips for smoother migration
- Keep the old Gulp build for a sprint; serve the same HTML with Webpack bundle side‑by‑side.
- Move JS first, then styles/images.
- Replace plugin chains with equivalent loaders one at a time.
- Use source maps (
devtool: 'source-map'
) to debug transpiled code. - Leverage webpack‑merge to separate dev and prod configs.
Webpack’s declarative approach cuts down boilerplate and enables advanced optimisations that are hard to replicate with ad‑hoc task runners.
Recent posts
- At-Least-Once vs. Exactly-Once - Understanding Message Delivery Guarantees
June 12, 2025
Learn about message delivery guarantees in distributed systems. Understand why most production systems implement at-least-once delivery with idempotency rather than attempting exactly-once delivery.
- How Idempotency Saves Your API from Chaos
June 11, 2025
Learn how to implement idempotency in your APIs to prevent duplicate actions and ensure data consistency. Includes practical examples with Supabase and Node.js.
- Vibe Coding ‑ Notes from the First Try
June 6, 2025
Quick lessons from spinning up a new blog with an AI pair‑programmer and Cursor.