Gulp vs. npm scripts and Vite
last modified November 15, 2026
In this article we compare Gulp 5 with npm scripts and with Vite. We build the same small site with each of them, look at what the configuration looks like, and at the end say when a task runner still makes sense.
The same site three times
The site is the one from Gulp static site build: two HTML pages, Sass partials, an ES module script and three images. The build should compile Sass, add vendor prefixes and minify the CSS, bundle and minify the script, minify the HTML and copy the images; the development mode should serve the site and update the browser when a source file changes. The Gulp version is in the other tutorial; here we write the two alternatives and compare all three.
The tools were tested on Node.js 22.19 with Gulp 5.0.1, esbuild 0.28, Sass 1.108 and Vite 8.3. For fairness the sources of the three projects are the same, except that Vite wants the paths in the pages to point to the source files, as we see below.
Gulp: the reference
The Gulp project has a gulpfile of 95 lines and a small image plugin of 29 lines. Each step is a JavaScript function, the steps are composed with series and
parallel, and the same file describes the development mode, with the watchers and the server. The tools are used through their Node.js APIs, so there is full control: conditions, loops,
custom plugins, and error handling are plain code. The price is that there is much of it to write and to learn, and the plugins can be unmaintained or can lag behind the tools they wrap.
The production build takes about one second, which includes the start of npx. This is the figure we compare below.
npm scripts: the tools directly
Almost every tool has a command line interface, and package.json can run commands in its scripts section. No task runner is needed:
Sass, PostCSS, esbuild and the HTML minifier are called by name. The commands in a script can be chained with &&; for running scripts in series and in parallel, we install
npm-run-all2, which provides run-s and run-p, and for watching chokidar-cli. We also use browser-sync as the server.
Installing the npm scripts project
The project is an ES module project like the others, but there is no Gulp among the dependencies.
$ mkdir gulp-npm $ cd gulp-npm $ npm init -y $ npm pkg set type=module $ npm i -D sass postcss postcss-cli autoprefixer cssnano esbuild html-minifier-terser browser-sync chokidar-cli npm-run-all2
The scripts
The whole build is in package.json. The build script cleans dist and then runs the four asset scripts in parallel;
the dev script builds, and runs three watchers and the server in parallel.
{
"name": "gulp-npm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rm -rf dist",
"css": "sass --no-source-map src/scss/main.scss dist/css/main.css && postcss dist/css/main.css --replace --no-map --use autoprefixer --use cssnano",
"js": "esbuild src/js/main.js --bundle --minify --target=es2020 --outfile=dist/js/main.js",
"html": "html-minifier-terser --input-dir src --output-dir dist --file-ext html --collapse-whitespace --remove-comments",
"img": "mkdir -p dist && cp -r src/img dist/img",
"assets": "run-p css js html img",
"build": "run-s clean assets",
"watch:scss": "chokidar 'src/scss/**/*.scss' -c 'npm run css --silent'",
"watch:js": "chokidar 'src/js/**/*.js' -c 'npm run js --silent'",
"watch:html": "chokidar 'src/*.html' -c 'npm run html --silent'",
"serve": "browser-sync start --server dist --files dist --no-ui --no-open --no-notify",
"dev": "run-s build && run-p watch:scss watch:js watch:html serve"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"devDependencies": {
"autoprefixer": "^10.6.2",
"browser-sync": "^3.0.4",
"chokidar-cli": "^3.0.0",
"cssnano": "^8.0.10",
"esbuild": "^0.28.2",
"html-minifier-terser": "^7.2.0",
"npm-run-all2": "^8.0.4",
"postcss": "^8.5.33",
"postcss-cli": "^12.0.0",
"sass": "^1.108.2"
}
}
The scripts clean and img use the Unix commands rm and cp, which do not exist in the Windows command prompt; the portable
solutions are packages such as rimraf and cpy-cli. The images are only copied, because there is no equally short command for optimising them.
The scripts name the tools in a way that is easy to read, but all options are strings, and there are no conditions: the production and the development variants need separate scripts.
Building with npm scripts
We run the build script and list the result. The sizes are the same as in the production build of Gulp, except for the images, which are copied. The --silent option hides the headers that npm prints before every script, and the
grep command removes the empty lines.
$ npm run build --silent 2>&1 | grep -v "^$"
dist/js/main.js 148b
⚡ Done in 2ms
$ find dist -type f -printf "%7s %p\n" | sort -k2
437 dist/about.html
382 dist/css/main.css
151 dist/img/icon.svg
8172 dist/img/logo.png
96702 dist/img/photo.jpg
481 dist/index.html
148 dist/js/main.js
Development with npm scripts
The dev script builds the site, then starts the watchers and the server. We start it, change a colour in a Sass file, and ask the server for the stylesheet.
The watcher watch:scss ran the css script, and Browsersync, which watches the dist directory, delivered the change. The commands below were run
in a second terminal while npm run dev was running in the first.
$ curl -s localhost:3000/css/main.css | grep -o '#2a6f97' | sort -u #2a6f97 $ sed -i 's/#2a6f97/#c0392b/' src/scss/_variables.scss $ sleep 3 $ curl -s localhost:3000/css/main.css | grep -o '#c0392b' | sort -u #c0392b $ sed -i 's/#c0392b/#2a6f97/' src/scss/_variables.scss $ sleep 2
Vite: the build tool for applications
Vite is not a task runner but a build tool with a development server. It knows HTML, CSS, Sass and JavaScript, bundles with a built-in bundler, and has
sensible defaults, so the configuration is short. The page is the entry point: the link and script elements point to the source files, and Vite follows them. Sass is not part of Vite, but Vite uses it when it finds a .scss file, so we install it too.
Installing the Vite project
The project has the dependencies vite and sass and three scripts: vite is the development server, vite build the production build, and vite preview serves the result.
$ mkdir gulp-vite $ cd gulp-vite $ npm init -y $ npm pkg set type=module $ npm i -D vite sass $ npm pkg set scripts.dev=vite scripts.build="vite build" scripts.preview="vite preview"
Configuring Vite
Our site has two pages, and Vite by default builds one, index.html, so the configuration lists both as inputs. The public directory contains the files that are copied to the output as they are,
here the images. The head of the page changes: the source paths start with a slash, and the script is a module.
import { defineConfig } from 'vite';
import { resolve } from 'node:path';
export default defineConfig({
build: {
rollupOptions: {
input: {
index: resolve(import.meta.dirname, 'index.html'),
about: resolve(import.meta.dirname, 'about.html')
}
}
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home</title>
<link rel="stylesheet" href="/src/scss/main.scss">
<script type="module" src="/src/js/main.js"></script>
</head>
<body>
<!-- site header -->
<header class="site-header">
<img src="img/logo.png" alt="Logo" width="64">
<nav>
<a href="index.html">Home</a>
<a href="about.html">About</a>
</nav>
</header>
<main>
<h1 id="title">Static site</h1>
<p>A small site built with Gulp 5.</p>
<img src="img/photo.jpg" alt="Photo" width="400">
</main>
</body>
</html>
The scripts and styles are those from the Gulp project. There is no configuration for Sass, vendor prefixes, minification or the bundler; the defaults work.
Building with Vite
The vite build command produces the output. The names of the CSS and JavaScript files contain a hash of the content, so the browsers cache them safely, which in Gulp is done with the plugins from
Gulp cache busting. The pages are modified to refer to the new names. The HTML is not minified, and the comment is still in the page; Vite leaves this to other tools. The bundle is larger than that of esbuild: Vite adds a small script
for the preloading of modules, which can be removed with the option build.modulePreload.
$ npm run build --silent
vite v8.3.8 building client environment for production...
transforming...
✓ 7 modules transformed.
rendering chunks...
computing gzip size...
dist/about.html 0.55 kB │ gzip: 0.34 kB
dist/index.html 0.63 kB │ gzip: 0.37 kB
dist/assets/main-K1EWGvRm.css 0.36 kB │ gzip: 0.22 kB
dist/assets/main-BduzzvWa.js 0.80 kB │ gzip: 0.45 kB
✓ built in 181ms
$ find dist -type f -printf "%7s %p\n" | sort -k2
558 dist/about.html
806 dist/assets/main-BduzzvWa.js
361 dist/assets/main-K1EWGvRm.css
151 dist/img/icon.svg
8172 dist/img/logo.png
96702 dist/img/photo.jpg
630 dist/index.html
$ grep -n "assets" dist/index.html
6: <script type="module" crossorigin src="/assets/main-BduzzvWa.js"></script>
7: <link rel="stylesheet" crossorigin href="/assets/main-K1EWGvRm.css">
Development with Vite
The development server of Vite does not bundle the files. It serves each module separately, the browser follows the imports, and Vite transforms a file when it is requested. The start is fast and a change of a
file updates only the affected module (hot module replacement) without reloading the page. We start vite, check that the page contains the client script, change the colour of the stylesheet, and
ask for the transformed Sass file; the log of the server notes the update.
$ curl -s localhost:5173/ | grep -c '@vite/client' 1 $ sed -i 's/#2a6f97/#c0392b/' src/scss/_variables.scss $ sleep 1 $ curl -s localhost:5173/src/scss/main.scss | grep -o '#c0392b' | sort -u #c0392b $ sed -i 's/#c0392b/#2a6f97/' src/scss/_variables.scss $ sleep 1
Build time
Finally we compare the time of the three production builds, each of which writes the output from scratch. The values are wall-clock times of one run on this machine, so they are only an indication. The Gulp build is one Node.js process, the npm script starts several, and Vite is one process.
$ NODE_ENV=production /usr/bin/time -f "%e s" npx gulp build --silent 2>&1 >/dev/null | tail -1 1.10 s $ /usr/bin/time -f "%e s" npm run build --silent 2>&1 >/dev/null | tail -1 1.16 s $ /usr/bin/time -f "%e s" npx vite build 2>&1 >/dev/null | tail -1 0.48 s
Comparison
The three approaches differ in what they assume about the project. The table summarises the differences we saw above.
| Gulp | npm scripts | Vite | |
|---|---|---|---|
| Configuration | JavaScript, 95 + 29 lines | scripts in package.json | 13 lines, mostly defaults |
| Control of the steps | full, in code | command lines, no logic | through options and plugins |
| Composition | series, parallel | &&, run-s, run-p | built in |
| Watching | watch() | extra tool (chokidar) | built in |
| Development server | Browsersync, set up by hand | Browsersync, set up by hand | built in, hot module replacement |
| Hashed file names | plugins | extra tools | built in |
| HTML minification | plugin | command line tool | not included |
| Files that are not part of a bundle | any pipeline | any command | copied from public |
| Custom transformations | write a plugin | write a script | write a plugin |
| Windows | works | shell commands need replacements | works |
When to use which
For an application with JavaScript modules, a framework or code splitting, Vite is the better choice: it has the bundler, the server and the hot reload built in, and we write almost no configuration. The static site of this tutorial also fits, but we have to add what Vite does not do, such as the minification of HTML or the processing of the images.
For a few steps, such as compiling Sass and bundling one script, the npm scripts are enough, they have no extra layer, and everybody understands them. As soon as the build has conditions, loops over files, many dependent steps, or needs shell commands that work on every system, the scripts become hard to read.
Gulp makes sense when the build is a pipeline of files rather than an application: a static site, a theme or a plugin for a CMS, documentation, assets from many sources that are renamed, concatenated, transformed and copied, or a project with its own special steps that are easy to express as a Transform stream. It is also a good tool when we already have a gulpfile, which keeps working for years; if we move to Vite, we use it for the bundling and keep Gulp for the tasks around, such as the deployment from Gulp zip and deploy.
Source
Vite guide, npm scripts, Gulp quick start
In this article we have built the same site with Gulp, with npm scripts and with Vite, compared the configuration, the output and the development workflow, and said which tool suits which kind of project. See also the Getting started with Gulp and Gulp static site build tutorials.
Author
List all Gulp tutorials.