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
63
votes
7 answers

How to run a gulp task from another task?

I am aware of the ability to declare dependencies that will run before the task, e.g. gulp.task('a', () => {}); gulp.task('b', () => {}); gulp.task('c', ['a', 'c'], () => {}); Tasks 'a' and 'b' will be run every time after task 'c' is called and…
Gajus
  • 69,002
  • 70
  • 275
  • 438
62
votes
7 answers

How to debug a Gulp task?

How do I debug a gulp task defined in my gulpfile.js with a debugger such as the Google Chrome debugger, stepping through the task's code line by line?
user2943490
  • 6,900
  • 2
  • 22
  • 38
62
votes
2 answers

gulp minify all css files to a single file

I have gulp task script as following, // loads various gulp modules var gulp = require('gulp'); var concat = require('gulp-concat'); var minifyCSS = require('gulp-minify-css'); var autoprefixer = require('gulp-autoprefixer'); var rename =…
Dipendra Gurung
  • 5,720
  • 11
  • 39
  • 62
61
votes
2 answers

Best way to filter files in gulp.watch?

I would like to watch all, but the .min.ext files in my directories with gulp.js. What is the best way to filter out those? Example: gulp.task('watch', function(e) { gulp.watch('./js/*.js', ['css']); // don't want to watch .min.js files. what is…
i--
  • 4,349
  • 2
  • 27
  • 35
60
votes
11 answers

Gulpjs combine two tasks into a single task

I currently have two tasks, that both compile sass files. I would still like to concat the two directories into separate files but it seems that it would be more maintainable if I could simply create a 'sass' task that would be responsible for all…
Noah Goodrich
  • 24,875
  • 14
  • 66
  • 96
60
votes
10 answers

How to run a task ONLY on modified file with Gulp watch

I have the current gulp task which I use in a gulpfile. Path are from a config.json and everything works perfectly: //Some more code and vars... gulp.task('watch', function() { gulp.watch([config.path.devfolder+"/**/*.png",…
soenguy
  • 1,332
  • 3
  • 11
  • 23
59
votes
2 answers

Why do I have to use vinyl-source-stream with gulp?

I am trying to use gulp and browserify to transform my .jsx files into .js files. var gulp = require('gulp'); var browserify = require('browserify'); var reactify = require('reactify'); gulp.task('js', function () { …
mc9
  • 6,121
  • 13
  • 49
  • 87
58
votes
5 answers

Running a shell command from gulp

I would like to run a shell command from gulp, using gulp-shell. I see the following idiom being used the gulpfile. Is this the idiomatic way to run a command from a gulp task? var cmd = 'ls'; gulp.src('', {read: false}) .pipe(shell(cmd, {quiet:…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
58
votes
1 answer

How can I write a simple gulp pipe function?

I've been trying for a day to write two pipe functions, one that compiles less files and another one that concats these files. I want to learn how to write transform streams/pipes for more complex plugins. So I want to know how to read data from…
Vlad Nicula
  • 3,577
  • 6
  • 32
  • 50
57
votes
6 answers

Gulp error: gulp.hasTask is not a function

I'm getting the following when I run "gulp". Looks like I have a mixed of CLI and Local version, not really sure how to solve this problem. cabox@box-codeanywhere:~/workspace/apps/web-ui$ gulp -v [22:44:23] CLI version 2.0.1 [22:44:23] Local…
user1187968
  • 7,154
  • 16
  • 81
  • 152
56
votes
11 answers

gulp task issue with nodejs v10.3.0 : src\node_contextify.cc:629: Assertion `args[1]->IsString()' failed

I recently updated my nodejs version to 10.30.0. Everything works fine. But my gulp build task not working which was working fine on older version(9.X). This is what I am getting. gulp[11376]: src\node_contextify.cc:629: Assertion…
M14
  • 1,780
  • 2
  • 14
  • 31
56
votes
4 answers

Have sass-lint ignore a certain line?

I'm using sass-lint with Gulp. How can I disable warnings for a particular style in my sass from the lint console output? I've found a similar question but I'm using sass-lint, not scss-lint: Having scss-lint ignore a particular line This is the…
Evanss
  • 23,390
  • 94
  • 282
  • 505
56
votes
2 answers

How can I use the path from gulp.src() in gulp.dest()?

Trying to create a gulp task that will pipe a bunch of files from different folders through LESS and then output them to a folder based on the original source. Consider this folder structure: Project +-- /Module_A | +- /less | | +- a.less | …
Adam
  • 738
  • 1
  • 5
  • 11
54
votes
1 answer

gulp: uglify and sourcemaps

I am using gulp. I would like to having one or multiple JS files (say jQuery) to combine them in one, minify it, and write it to a distribution folder. This is how I do it: minifyJS(['/js/myModule.file1.js', '/js/myModule.file2.js'],…
serge
  • 13,940
  • 35
  • 121
  • 205
53
votes
9 answers

How to minify ES6 functions with gulp-uglify?

When I run gulp I get the following error: [12:54:14] { [GulpUglifyError: unable to minify JavaScript] cause: { [SyntaxError: Unexpected token: operator (>)] message: 'Unexpected token: operator (>)', filename: 'bundle.js', line: 3284, col: 46, …
Don
  • 3,876
  • 10
  • 47
  • 76