Questions tagged [gulp]

Gulp is a JavaScript build system, Node.js-based task runner like Grunt. Gulp uses streams and code-over-configuration for a simpler and more intuitive build process.

Gulp is a build system, -based task runner like . It can automate common tasks during your development process. Gulp uses the streams-concept and code-over-configuration for a simpler and more intuitive build process. The code-over-configuration concept can create more readable and simple tasks, despite tasks which are highly over-configured.

Install

First you have to install gulp globally:

npm install gulp -g

After that you should add gulp to your project (package.json file):

npm install --save-dev gulp

Then you should create a file named gulpfile.js and define your tasks in that. Any valid node.js code can be used in gulpfile.js (like defining functions, importing extra modules, etc.).

After you created your tasks, you should export them (as you would in any other module). And then you can run the task by running gulp <task name> in terminal (in the project folder). Running gulp without specifying would run the default task if present (the main task is usually named default to be more convenient)

Example

const gulp = require('gulp');
const less = require('gulp-less');
const autoprefix = require('gulp-autoprefixer');

gulp.task('css', () => {
   gulp.src('assets/app.less')
      .pipe(less())
      .pipe(autoprefix('last 2 version', 'ie 8', 'ie 9'))
      .pipe(gulp.dest('build'));
});

And to run this task, run this in terminal:

$ gulp css

Useful Links

Related Tags

12677 questions
119
votes
6 answers

Gulp Error: Cannot find module 'jshint/src/cli'

So I've got a fresh install of El Capitan and I'm giving these task runners another go. I'm following sitepoint's An introduction to Gulp.js, but I'm stuck on step four, when I try to run gulp jshint I get "Error: Cannot find module…
lateralaus
  • 1,523
  • 3
  • 11
  • 11
119
votes
4 answers

What is the ** glob character?

I have this path in my react gulpfile: var path = { HTML: 'src/index.html', ALL: ['src/js/*.js', 'src/js/**/*.js', 'src/index.html'], JS: ['src/js/*.js', 'src/js/**/*.js'], MINIFIED_OUT: 'build.min.js', DEST_SRC: 'dist/src', DEST_BUILD:…
Jwan622
  • 11,015
  • 21
  • 88
  • 181
115
votes
3 answers

How to uglify output with Browserify in Gulp?

I tried to uglify output of Browserify in Gulp, but it doesn't work. gulpfile.js var browserify = require('browserify'); var gulp = require('gulp'); var uglify = require('gulp-uglify'); var source =…
Nik Terentyev
  • 2,270
  • 3
  • 16
  • 23
113
votes
2 answers

gulp globbing- how to watch everything below directory

This is a pretty dumb question, but I haven't really been able to find a satisfactory answer: How do I use gulp globbing to select all files in all subdirectories below a certain directory? I've tried: './src/less' './src/less/' './src/less/*' None…
Jehan
  • 2,701
  • 2
  • 23
  • 28
109
votes
11 answers

How to go back 1 folder level with __dirname?

I am using gulp-karma and facing a simple problem but cannot seems to find what i am doing wrong . gulp.task('test', function (done) { karma.start({ configFile: __dirname + '..\\test\\' +'\karma.conf.js', singleRun: true },…
Malik
  • 3,520
  • 7
  • 29
  • 42
109
votes
4 answers

Karma: Running a single test file from command line

So, I've been looking all over for this, found "similar" answers here, but not exactly what I want. Right now if I want to test a single file with karma, I need to do fit(), fdescribe() on the file in question... However, what I do want is to be…
Gonçalo Vieira
  • 2,249
  • 2
  • 19
  • 39
108
votes
5 answers

Modify file in place (same dest) using Gulp.js and a globbing pattern

I have a gulp task that is attempting to convert .scss files into .css files (using gulp-ruby-sass) and then place the resulting .css file into the same place it found the original file. The problem is, since I'm using a globbing pattern, I don't…
Dan-Nolan
  • 6,594
  • 4
  • 27
  • 32
106
votes
2 answers

Multiple file extensions within the same directory using Gulp

So I have a gulpfile.js setup. In an images folder I have a few images, some are pngs, some jpgs and some gifs. I want to target all the pngs, jpgs and gifs in the images folder. I could use **/* to target everything in the folder, but I don't want…
mildrenben
  • 3,675
  • 5
  • 23
  • 37
106
votes
4 answers

Javascript: get package.json data in gulpfile.js

Not a gulp-specific question per-se, but how would one get info from the package.json file within the gulpfile.js; For instance, I want to get the homepage or the name and use it in a task.
Lane
  • 6,532
  • 5
  • 28
  • 27
102
votes
5 answers

Task Runner Explorer can't load tasks

I'm using VS2015 and Gulp. I open the Task Runner Explorer and hit refresh, and this shows up in the log: Failed to run "C:\Projects\Test\Gulpfile.js"... cmd.exe /c gulp --tasks-simple Error: `libsass` bindings not found in…
Josh M.
  • 26,437
  • 24
  • 119
  • 200
101
votes
2 answers

Use gulp to select and move directories and their files

I'm currently using gulp to call a bash script that cleans my dist/ directory and moves the appropriate files to the clean directory. I would like this to be done with gulp because I am not sure the script would work on a non *nix file system. So…
makenova
  • 3,579
  • 3
  • 17
  • 20
100
votes
12 answers

Gulp command not found after install

I installed gulp(globally) and it looks like it worked because it ran this code: ├── tildify@0.2.0 ├── interpret@0.3.5 ├── pretty-hrtime@0.2.1 ├── deprecated@0.0.1 ├── archy@0.0.2 ├── minimist@0.2.0 ├── semver@2.3.2 ├── orchestrator@0.3.7…
iluvpinkerton
  • 3,058
  • 3
  • 14
  • 17
99
votes
3 answers

console.log to stdout on gulp events

I want to log to stdout (the config environment) when a gulp task is running or has run. Something like this: gulp.task('scripts', function () { var enviroment = argv.env || 'development'; var config = gulp.src('config/' + enviroment + '.json') …
Rimian
  • 36,864
  • 16
  • 117
  • 117
99
votes
10 answers

gulp.run is deprecated. How do I compose tasks?

Here is a composed task I don't know how to replace it with task dependencies. ... gulp.task('watch', function () { var server = function(){ gulp.run('jasmine'); gulp.run('embed'); }; var client = function(){ gulp.run('scripts'); …
toutpt
  • 5,145
  • 5
  • 38
  • 45
98
votes
8 answers

How to get the available tasks list in gulp

Hi Previously I used the grunt in that I want to know the available tasks use grunt --help. But same as in gulp use gulp --help it doesn't show. What is the command to know the available tasks list in gulp
vamsikrishnamannem
  • 4,817
  • 5
  • 23
  • 34