GitHub - gulpjs/gulp: A toolkit to automate & enhance your workflow (original) (raw)

The streaming build system

NPM version Downloads Build Status Coveralls Status

What is gulp?

Installation

Follow our Quick Start guide.

Roadmap

Find out about all our work-in-progress and outstanding issues at https://github.com/orgs/gulpjs/projects.

Documentation

Check out the Getting Started guide and API docs on our website!

Excuse our dust! All other docs will be behind until we get everything updated. Please open an issue if something isn't working.

Sample gulpfile.js

This file will give you a taste of what gulp does.

var gulp = require('gulp'); var less = require('gulp-less'); var babel = require('gulp-babel'); var concat = require('gulp-concat'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); var cleanCSS = require('gulp-clean-css'); var del = require('del');

var paths = { styles: { src: 'src/styles//*.less', dest: 'assets/styles/' }, scripts: { src: 'src/scripts//*.js', dest: 'assets/scripts/' } };

/* Not all tasks need to use streams, a gulpfile is just another node program

/*

function scripts() { return gulp.src(paths.scripts.src, { sourcemaps: true }) .pipe(babel()) .pipe(uglify()) .pipe(concat('main.min.js')) .pipe(gulp.dest(paths.scripts.dest)); }

function watch() { gulp.watch(paths.scripts.src, scripts); gulp.watch(paths.styles.src, styles); }

/*

/*

Use latest JavaScript version in your gulpfile

Gulp provides a wrapper that will be loaded in your ESM code, so you can name your gulpfile as gulpfile.mjs or with "type": "module" specified in your package.json file.

And here's the same sample from above written in ESNext.

import { src, dest, watch } from 'gulp'; import less from 'gulp-less'; import babel from 'gulp-babel'; import concat from 'gulp-concat'; import uglify from 'gulp-uglify'; import rename from 'gulp-rename'; import cleanCSS from 'gulp-clean-css'; import del from 'del';

const paths = { styles: { src: 'src/styles//*.less', dest: 'assets/styles/' }, scripts: { src: 'src/scripts//*.js', dest: 'assets/scripts/' } };

/*

/*

export function scripts() { return src(paths.scripts.src, { sourcemaps: true }) .pipe(babel()) .pipe(uglify()) .pipe(concat('main.min.js')) .pipe(dest(paths.scripts.dest)); }

/*

const build = gulp.series(clean, gulp.parallel(styles, scripts)); /*

Incremental Builds

You can filter out unchanged files between runs of a task using the gulp.src function's since option and gulp.lastRun:

const paths = { ... images: { src: 'src/images/**/*.{jpg,jpeg,png}', dest: 'build/img/' } }

function images() { return gulp.src(paths.images.src, {since: gulp.lastRun(images)}) .pipe(imagemin()) .pipe(gulp.dest(paths.images.dest)); }

function watch() { gulp.watch(paths.images.src, images); }

Task run times are saved in memory and are lost when gulp exits. It will only save time during the watch task when running the images task for a second time.

Want to contribute?

Anyone can help make this project better - check out our Contributing guide!