Documentation Index
Fetch the complete documentation index at: https://mintlify.com/jpachecox/setup-gulp/llms.txt
Use this file to discover all available pages before exploring further.
gulpfile.js is the central configuration file for the entire Setup Gulp build pipeline. Every source glob, output destination, task definition, and plugin option lives here. Understanding its structure lets you adapt the project to any asset layout, extend it with custom tasks, and fine-tune how aggressively files are optimised before they reach the browser.
The paths object
The paths object is the single authoritative place for all source globs and output directories. Updating a value here propagates to every task that references it — you never need to hunt through individual task definitions.
gulpfile.js
| Key | Default glob | What to change it to |
|---|---|---|
sassComponents | ./src/scss/components/*.scss | Any directory that holds per-component stylesheet partials |
sassSections | ./src/scss/sections/*.scss | Any directory that holds per-section stylesheet partials |
sass | ./src/scss/*.scss | The root SCSS entry files that import partials |
css | ./src/css/*.css | The intermediate compiled CSS folder — rarely changed |
jsComponents | ./src/js/components/*.ts | Per-component TypeScript source files |
jsSections | ./src/js/sections/*.ts | Per-section TypeScript source files |
js | ./src/js/*.ts | Root-level TypeScript entry files |
font | ./src/fonts/**/* | Any font format directory; the **/* glob picks up all sub-folders |
img | ./src/img/**/*.+(png|jpg|jpeg|gif|svg) | Extend the extension list (e.g. add webp) or point to a different source folder |
dest | ./assets | Change to a Shopify theme directory such as ../my-theme/assets to deploy directly |
root | ./index.html | The HTML entry point watched for full-page reloads by BrowserSync |
BrowserSync configuration
BrowserSync is initialised inside theserve task and handles live reloading during development.
gulpfile.js
baseDir: './'— serves the project from the repository root soindex.htmlis reachable athttp://localhost:3000.paths.rootwatch — triggers a full page reload wheneverindex.htmlchanges.- CSS streaming — Sass and CSS tasks pipe through
browserSync.stream()at the end of the pipeline, injecting updated styles directly into the browser without a full reload.
server option with a proxy:
gulpfile.js
The watch task
The watch task registers a file watcher for every source glob in paths. Each watcher wraps its corresponding task in gulp.series so file events are processed sequentially — this prevents race conditions when a rapid sequence of saves would otherwise queue overlapping compilations.
gulpfile.js
gulp.series — the same pattern as every other watcher — because the copy and optimisation operations are fast enough that sequential processing is fine and avoids partial writes to paths.dest.
Run the watcher with:
The build task
The build task runs all ten compilation and optimisation tasks in parallel using gulp.parallel. Running them concurrently cuts total build time significantly compared to a sequential run.
gulpfile.js
cleanAssets is included in the parallel group rather than run before the others. This means cleaning and compilation start at the same time. If you need to guarantee the output directory is fully empty before any new file is written — for example, to avoid stale files surviving a rename — swap gulp.parallel for a gulp.series('cleanAssets', gulp.parallel(...)) pattern.
Run a full build with:
Error handling
ThehandleErrors function is passed as the errorHandler option to plumber in every task. When a task fails, it fires a desktop notification and beeps the system speaker before exiting.
gulpfile.js
notify.onError is provided by gulp-notify and triggers an OS-level notification (macOS Notification Centre, Linux notify-send, etc.) with the error message interpolated into the title string.
gutil.beep() comes from gulp-util, which is a deprecated package that has not been maintained since 2018. It still works at runtime because no replacement for beep() has been widely adopted, but you can safely remove the gutil.beep() call and the gulp-util import if desktop audio feedback is not needed.
Image optimisation settings
Theimages task pipes every matched file through gulp-imagemin with per-format plugins. Each plugin exposes options you can tune to balance file size against processing time and visual quality.
gulpfile.js
mozjpeg
quality(0–100) — lower values produce smaller files with more visible compression artefacts.75is a good default for web; drop to60for thumbnails.progressive: true— encodes the JPEG in progressive scans so the browser can render a blurry preview before the full image loads.
optipng
optimizationLevel(0–7) — higher levels apply more aggressive deflate strategies. Level5balances speed and size well; use7in a CI pipeline where build time is less important.
gifsicle
interlaced: true— encodes the GIF so browsers can display a coarse version while the rest of the file downloads, matching the progressive behaviour of JPEG.
svgo
removeViewBox: true— strips theviewBoxattribute from SVGs whose dimensions are set on the element itself. Disable this if your SVGs need to scale responsively.cleanupIDs: false— leave internal IDs intact. Enabling this can break SVGs that use<use>references or CSS selectors targeting specific IDs.
Adding a new task
Adding a task involves three steps: defining the task function, registering a watcher so it runs on file changes during development, and including it in thebuild task so it runs during production builds.
gulpfile.js
watch and build task definitions. The plumber call ensures the watcher keeps running even if the task throws an error — without it, a syntax mistake in a source file would kill the entire process.
Browserslist
Thebrowserslist field in package.json controls which browsers Autoprefixer and Babel’s @babel/preset-env target when adding vendor prefixes and transpiling modern JavaScript syntax.
package.json
"last 2 versions" targets the two most recent releases of every major browser, which covers the vast majority of users while keeping the CSS and JS output lean. You can be more specific when your audience requires it:
package.json
npx browserslist in the project root at any time to see the exact list of browsers the current query resolves to.
gulpfile.js is written with ES module syntax (import/export). The "type": "module" field must remain present in package.json — removing it will cause Node.js to treat the file as CommonJS and throw a syntax error on the first import statement.