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
95
votes
1 answer

Why does gulp.src not like being passed an array of complete paths to files?

I'm attempting to pass gulp.src an array of files that I want it to deal with. This is the array as it stands. ['bower_components/jquery/jquery.js', 'bower_components/superscrollorama/js/greensock/TweenMax.min.js', …
morganesque
  • 953
  • 1
  • 6
  • 4
94
votes
8 answers

UglifyJS throws unexpected token: keyword (const) with node_modules

A small project I started make use a node module (installed via npm) that declares const variables. Running and testing this project is well, but browserify fails when UglifyJS is executed. Unexpected token: keyword (const) Here is a generic Gulp…
Yanick Rochon
  • 51,409
  • 25
  • 133
  • 214
93
votes
7 answers

Local gulp not found (Try running: npm install gulp)

I created a module (webapp-module-storage) which has the following definitions: package.json { "dependencies": { ... }, "devDependencies": { "gulp": "^3.9.1", ... }, "name": "webapp-module-storage", "scripts": { …
Benny Code
  • 51,456
  • 28
  • 233
  • 198
92
votes
5 answers

Looking for way to copy files in gulp and rename based on parent directory

For each module I have some files that need to be copied over to the build directory, and am looking for a way to minimize the repeated code from this: gulp.src('./client/src/modules/signup/index.js') …
chris
  • 4,332
  • 5
  • 41
  • 61
91
votes
2 answers

Using Grunt, Bower, Gulp, NPM with Visual Studio 2015 for a ASP.NET 4.5 Project

Visual Studio 2015 comes with built in support for tools like Grunt, Bower, Gulp and NPM for ASP.NET 5 projects. However when I create a ASP.NET 4.5.2 project using Visual Studio 2015 it doesn't use these tools. I'd like to use bower instead of…
Robert Hegner
  • 9,014
  • 7
  • 62
  • 98
88
votes
12 answers

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' - Gulp

Consider the following two files: app.js import Game from './game/game'; import React from 'react'; import ReactDOM from 'react-dom'; export default (absPath) => { let gameElement = document.getElementById("container"); if…
TheWebs
  • 12,470
  • 30
  • 107
  • 211
88
votes
4 answers

No local gulp install found even after installing npm install -g gulp

I tried to install gulp by npm install -g gulp The output seems to be something like this. (i have skipped some logs) npm http 304 https://registry.npmjs.org/string_decoder npm http 304 https://registry.npmjs.org/lodash._htmlescapes /usr/bin/gulp…
harikrish
  • 2,009
  • 3
  • 19
  • 37
87
votes
12 answers

Error: Couldn't find preset "es2015" relative to directory "/Users/username"

I get the following error when trying to use gulp-babel: Error: Couldn't find preset "es2015" relative to directory "/Users/username" I have the es2015 preset installed globally and locally so can't see why this would be an issue. Below is my…
Brian Douglas
  • 984
  • 1
  • 6
  • 8
85
votes
3 answers

How to copy multiple files and keep the folder structure with Gulp

I am trying to copy files from one folder to another folder using Gulp: gulp.task('move-css',function(){ return gulp.src([ './source/css/one.css', './source/other/css/two.css' ]).pipe(gulp.dest('./public/assets/css/')); }); The above…
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
82
votes
13 answers

'gulp' is not recognized as an internal or external command

I am trying to use Gulp and Node.Js to stream my process for minifying and concatenating CSS/JS files for production. Here is what I have done. I installed Node.Js on my Windows 7 machine. Installed Gulp globally using this command npm install -g…
Junior
  • 11,602
  • 27
  • 106
  • 212
81
votes
4 answers

Gulp-autoprefixer throwing ReferenceError: Promise is not defined

I try to make a gulp compile my sass then autoprefixit with gulp-autoprefixer but i'm getting an error. var gulp = require('gulp'), sass = require('gulp-sass'), autoprefixer = require('gulp-autoprefixer'); gulp.task('test', function(){ …
Matei
  • 1,783
  • 1
  • 14
  • 17
80
votes
8 answers

Uglify SyntaxError: Unexpected token: punc ())

I am trying to use gulp in order to minify a folder containing JS files. However, one of the files has the above error, preventing it from being minified. I managed to catch and print the error, which I've partially printed here: JS_Parse_Error { …
Alexander
  • 999
  • 1
  • 9
  • 18
80
votes
18 answers

Error: Cannot find module 'gulp-sass'

When I compile with gulp, I got an error like below. How can I fix it? module.js:339 throw err; ^ Error: Cannot find module 'gulp-sass' at Function.Module._resolveFilename (module.js:337:15) at Function.Module._load (module.js:287:25) at…
Htet Win
  • 801
  • 1
  • 6
  • 4
77
votes
3 answers

Browserify, Babel 6, Gulp - Unexpected token on spread operator

I'm trying to get my Browserify/Babelify/Gulp working in my project, but it won't take the spread operator. I got this error from my gulpfile: [SyntaxError: /Users/mboutin2/Desktop/Todo-tutorial/src/reducers/grocery-list-reducers.js: Unexpected…
Mike Boutin
  • 5,297
  • 12
  • 38
  • 65
77
votes
9 answers

How do you create a file from a string in Gulp?

In my gulpfile I have a version number in a string. I'd like to write the version number to a file. Is there a nice way to do this in Gulp, or should I be looking at more general NodeJS APIs?
Daryl
  • 1,023
  • 1
  • 8
  • 9