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
52
votes
11 answers

How do I install gulp 4

I've been using gulp-watch. The current version of gulp-watch relies on the call gulp.parrallel. This call is only available from gulp 4. However gulp 4 is not available via the npm repo. npm info gulp dist-tags returns: { latest: '3.9.0' }. I can…
dave dave
  • 947
  • 3
  • 10
  • 15
50
votes
9 answers

Can I use a Gulp task with multiple sources and multiple destinations?

I have the following in my gulpfile.js: var sass_paths = [ './httpdocs-site1/media/sass/**/*.scss', './httpdocs-site2/media/sass/**/*.scss', './httpdocs-site3/media/sass/**/*.scss' ]; gulp.task('sass', function() { …
David Angel
  • 1,001
  • 2
  • 10
  • 21
50
votes
3 answers

How to run bash commands in gulp?

I want to add some bash commands at the end of gulp.watch function to accelerate my development speed. So, I am wondering if it is possible. Thanks!
houhr
  • 579
  • 1
  • 5
  • 9
48
votes
1 answer

What exactly does .pipe() mean in gulp?

I am relatively new to gulp, and I was wondering what exactly does the .pipe() do in a gulp task? I've gathered that it usually runs after a return and after .src, but there must be more to it than that. I've been unable to find anything on the web…
Arlo
  • 963
  • 3
  • 11
  • 20
48
votes
3 answers

How to set gulp.dest() in same directory as pipe inputs?

I need all the found images in each of the directories to be optimized and recorded into them without setting the path to the each folder separately. I don't understand how to make that. var gulp = require('gulp'); var imageminJpegtran =…
Andrey Vaganov
  • 1,684
  • 1
  • 12
  • 18
48
votes
5 answers

Using the original URL, not proxy, with browser-sync

Recently switched from Grunt.js to Gulp.js as multiple people told me how much better and faster it wa (it's true!). I have added BrowserSync to my Gulpfile.js, making it easier to test on multiple devices. It works great and was simple to setup.…
Tom Oakley
  • 6,065
  • 11
  • 44
  • 73
48
votes
3 answers

gulp-newer vs gulp-changed

What're the differences between them? gulp-newer: gulp.src(imgSrc) .pipe(newer(imgDest)) .pipe(imagemin()) .pipe(gulp.dest(imgDest)); gulp-changed: gulp.src(SRC) .pipe(changed(DEST)) // ngmin will only get the files that //…
Frank Fang
  • 2,102
  • 3
  • 24
  • 47
48
votes
8 answers

How to deploy node that uses Gulp to heroku

I'm using gulp and also gulp plugins like gulp-minify-css, gulp-uglify etc (that listed as npm dependencies for my application). Also I don't commit npm_modules folder and public folder, where all generated files are. And I can't figure out how to…
Inanc Gumus
  • 25,195
  • 9
  • 85
  • 101
48
votes
3 answers

how to make Gulp stop watching files

How do you stop files from being watched? I have not seen the method in the docs which seems a bit odd to me.
Richard
  • 4,516
  • 11
  • 60
  • 87
46
votes
2 answers

yarn upgrade to fix yarn audit errors

So, as of now, it appears that there is no yarn audit --fix, so I am trying to figure out how to go about fixing my yarn audit errors. I have tried a yarn upgrade which has fixed some of the errors (which is great), but there are still several…
Ken Bigler
  • 587
  • 1
  • 4
  • 15
46
votes
4 answers

What are the differences between Grunt, Gulp.js and Bower? Why & when to use them?

What are the differences between Grunt, Gulp.js and Bower? Why & when and how to use them? I've seen nowadays, most of the front-end project using the above tools, though I am using them like in my recent project I am using gulp to build HTML, CSS…
Subodh Ghulaxe
  • 18,333
  • 14
  • 83
  • 102
46
votes
2 answers

gulp babel, exports is not defined

Consider the following example code (and maybe I am doing it wrong?) var FlareCurrency = { }; export {FlareCurrency}; I have the following task: gulp.task("compile:add-new-currency-minified", function(){ return…
TheWebs
  • 12,470
  • 30
  • 107
  • 211
46
votes
3 answers

Gulp TypeError: Arguments to path.join must be strings

I have i problem with gulp-ruby-sass. When i try to run the watch task and change some .sass files it occurs error: TypeError: Arguments to path.join must be strings Here is my gulpfile.js var gulp = require('gulp'); var jade =…
Andrew Gnilitskiy
  • 462
  • 1
  • 4
  • 8
45
votes
3 answers

How to prepare release version with SystemJS and Gulp?

I use SystemJS in my Angular2 project. I use tsconfig file for TypeScript. I want to use gulp to concat and minify my code for production version. I am having an issues with concating the code: each time I try to concat files I get either 'angular'…
uksz
  • 18,239
  • 30
  • 94
  • 161
44
votes
6 answers

How to clean a project correctly with gulp?

On the gulp page there is the following example: gulp.task('clean', function(cb) { // You can use multiple globbing patterns as you would with `gulp.src` del(['build'], cb); }); gulp.task('scripts', ['clean'], function() { // Minify and copy…
Jan Hommes
  • 5,122
  • 4
  • 33
  • 45