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

12395 questions
1994
votes
7 answers

NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. Webpack

I'm trying to summarize my knowledge about the most popular JavaScript package managers, bundlers, and task runners. Please correct me if I'm wrong: npm & bower are package managers. They just download the dependencies and don't know how to build…
VB_
  • 43,322
  • 32
  • 111
  • 238
624
votes
38 answers

How to fix "ReferenceError: primordials is not defined" in Node.js

I have installed Node.js modules by 'npm install', and then I tried to do gulp sass-watch in a command prompt. After that, I got the below response. [18:18:32] Requiring external module babel-register fs.js:27 const { Math, Object, Reflect } =…
Ramesh
  • 6,403
  • 3
  • 15
  • 13
546
votes
57 answers

Stylesheet not loaded because of MIME-type

I'm working on a website that uses gulp to compile and browser sync to keep the browser synchronised with my changes. The gulp task compiles everything properly, but on the website, I'm unable to see any style, and the console shows this error…
Nick
  • 10,791
  • 6
  • 40
  • 82
404
votes
15 answers

How to run Gulp tasks sequentially one after the other

in the snippet like this: gulp.task "coffee", -> gulp.src("src/server/**/*.coffee") .pipe(coffee {bare: true}).on("error",gutil.log) .pipe(gulp.dest "bin") gulp.task "clean",-> gulp.src("bin", {read:false}) .pipe…
iLemming
  • 30,282
  • 53
  • 181
  • 302
373
votes
11 answers

Is it possible to pass a flag to Gulp to have it run tasks in different ways?

Normally in Gulp tasks look like this: gulp.task('my-task', function() { return gulp.src(options.SCSS_SOURCE) .pipe(sass({style:'nested'})) .pipe(autoprefixer('last 10 version')) .pipe(concat('style.css')) …
asolberg
  • 5,992
  • 9
  • 29
  • 44
298
votes
7 answers

Why do we need to install gulp globally and locally?

2 manuals about gulp say that I need to install gulp first globally (with -g flag) and then one more time locally. Why do I need this?
Stepan Suvorov
  • 21,636
  • 25
  • 93
  • 166
266
votes
16 answers

Gulp error: The following tasks did not complete: Did you forget to signal async completion?

I have the following gulpfile.js, which I'm executing via the command line gulp message: var gulp = require('gulp'); gulp.task('message', function() { console.log("HTTP Server Started"); }); I'm getting the following error message: [14:14:41]…
John Deighan
  • 3,502
  • 4
  • 14
  • 15
266
votes
17 answers

Try reinstalling `node-sass` on node 0.12?

I would like to use google web starter kit. I installed node.js v0.12.0, node-sass & gulp. And then ran: $ sudo npm install When I typed gulp serve then got this error: Using gulpfile ~/web-starter-kit/gulpfile.js Starting 'styles'... 'styles'…
Takagi Akihiro
  • 2,661
  • 2
  • 9
  • 5
264
votes
9 answers

After installation of Gulp: “no command 'gulp' found”

After installing gulp.js via npm, I receive a no command 'gulp' found error when running the gulp command from the same directory it was installed into. When looking under the node_modules/.bin/ directory, I can see the gulp executable there. Is…
AndrewMcLagan
  • 11,928
  • 19
  • 75
  • 144
262
votes
3 answers

Node update a specific package

I want to update my Browser-sync without updating all my node packages. How can I achieve this? My current version of Browser-sync does not have the Browser-sync GUI :( ├─┬ browser-sync@1.9.2 │ ├── browser-sync-client@1.0.2
Samuel
  • 3,941
  • 5
  • 20
  • 33
261
votes
12 answers

How to watch and reload ts-node when TypeScript files change

I'm trying to run a dev server with TypeScript and an Angular application without transpiling ts files every time. I found that I can do the running with ts-node but I want also to watch .ts files and reload the app/server as I would do with…
235
votes
40 answers

gulp command not found - error after installing gulp

I've installed gulp both globally and locally using npm install gulp npm install gulp -g npm install gulp-util npm install gulp-util -g When try to run gulp i get 'gulp' is not recognized as an internal or external command, operable program or…
pedalpete
  • 19,318
  • 41
  • 115
  • 225
235
votes
2 answers

Excluding files/directories from Gulp task

I have a gulp rjs task that concatenates and uglifies all my custom .JS files (any non vendor libraries). What i am trying to do, is exclude some files/directories from this task (controllers and directives). Heres my tree: - application -…
Oam Psy
  • 8,309
  • 27
  • 87
  • 140
207
votes
13 answers

Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style

When using eslint in the gulp project i have encountered a problem with error like this Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style and I am using Windows environment for the running gulp and the entire error log is given below …
SaiKiran
  • 4,819
  • 10
  • 39
  • 66
207
votes
6 answers

How to prevent moment.js from loading locales with webpack?

Is there any way you can stop moment.js from loading all the locales (I just need English) when you're using webpack? I'm looking at the source and it seems that if hasModule is defined, which it is for webpack, then it always tries to require()…
epelc
  • 4,175
  • 5
  • 18
  • 26
1
2 3
99 100