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

How to Gulp-Watch Multiple files?

I have something like this: gulp.task('default', ['css', 'browser-sync'] , function() { gulp.watch(['sass/**/*.scss', 'layouts/*.css'], function() { gulp.run('css'); }); }); but it does not work, because it watches two…
LoveAndHappiness
  • 9,735
  • 21
  • 72
  • 106
70
votes
5 answers

How can I set an environment variable as gulp task?

I don't want type the extra arguments NODE_ENV='production' gulp every time I run gulp to set an environment variable. I would rather set the environment variable from within gulp via a task. What would be a good way to achieve this?
chacham15
  • 13,719
  • 26
  • 104
  • 207
70
votes
3 answers

Gulp minify multiple js files to one

I am new to Gulp and wondering how can I minify (concatinate) my collection to single file instead of every file separately. Example var gulp = require('gulp'); var uglify = require('gulp-uglify'); gulp.task('minify', function () { gulp.src([ …
Stan
  • 25,744
  • 53
  • 164
  • 242
69
votes
4 answers

npm install multiple package names

What does it do when I run this command: npm install --save-dev package1 package2 It is definitely not installing multiple packages, but it looks to be essential. (For example https://www.browsersync.io/docs/gulp) For me it throws following…
Lukáš Řádek
  • 1,273
  • 1
  • 11
  • 23
69
votes
8 answers

cannot find module "lodash"

Today I tried to learn more about Google Web Starter Kit so I followed these instructions and after a lot of fight and problem I just tried to start a local server (the first task we’ll look at is: $ gulp serve.) and received this…
Bosko Skrbina
  • 713
  • 1
  • 5
  • 5
69
votes
1 answer

Glob matching, exclude all JS files

I'm a new user to gulp.js. I'd like to move all of my non-javascript files to a build directory. What I've got right now is this: //Test copy gulp.task('test-copy', function() { gulp.src(['myProject/src/**/*.!(js|map|src)']) …
AlexZ
  • 11,515
  • 3
  • 28
  • 42
67
votes
14 answers

How can Gulp be restarted upon each Gulpfile change?

I am developing a Gulpfile. Can it be made to restart as soon as it changes? I am developing it in CoffeeScript. Can Gulp watch Gulpfile.coffee in order to restart when changes are saved?
coool
  • 8,085
  • 12
  • 60
  • 80
66
votes
3 answers

Gulp - copy and rename a file

I'm extremely new to Gulp. I'm basically trying to watch for a modified JavaScript file, and then make a new copy of it with a new name. (eventually there'll be some processing on it, but Rome wasn't built in a day). My (naive) attempt is…
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
65
votes
18 answers

How to solve npm install error “npm ERR! code 1”

I'm trying to install Gulp.js and when I write npm install I get this issue: npm ERR! code 1 npm ERR! path D:\www\wegrow\node_modules\node-sass npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js npm…
Wojciech Bałucki
  • 653
  • 1
  • 4
  • 5
65
votes
2 answers

Can you remove a folder structure when copying files in gulp?

If I use : gulp.src(['app/client/**/*.html']) .pipe(gulp.dest('dist')); The folder structure in which my .html files were in, is maintained in the dist folder, but I would like to remove the folder structure completely and just a flat hierarchy…
i_am_elliot
  • 653
  • 1
  • 5
  • 6
65
votes
5 answers

How to save a stream into multiple destinations with Gulp.js?

const gulp = require('gulp'); const $ = require('gulp-load-plugins')(); const source = require('vinyl-source-stream'); const browserify = require('browserify'); gulp.task('build', () => browserify('./src/app.js').bundle() …
Konstantin Tarkus
  • 37,618
  • 14
  • 135
  • 121
64
votes
1 answer

Gulp uglify output min.js

The js file being compressed is output with the same filename. gulp.task('compressjs', function () { gulp.src('app/**/*.js') .pipe(uglify()) .pipe(gulp.dest('dist')); }); How can I have it output the file with min.js at the back?
user1995781
  • 19,085
  • 45
  • 135
  • 236
64
votes
10 answers

Issue running karma task from gulp

I am trying to run karma tests from gulp task and I am getting this error: Error: 1 at formatError (C:\Users\Tim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:161:10) at Gulp.
Timur
  • 6,668
  • 1
  • 28
  • 37
63
votes
8 answers

GulpUglifyError:Unable to minify JavaScript

I am trying to minify my script files for which i am using gulp task runner And I am trying gulp-uglify plugin Code: gulp.task('concat', function() { return gulp.src('app/**/*.js') // .pipe(concat('script.js')) .pipe(uglify()) …
swathi anupuram
  • 795
  • 1
  • 7
  • 14
63
votes
11 answers

How to delete compiled JS files from previous typescript(.ts) files?

I am following Angular 2 quick start tutorial. Following is my folder structure - ├── gulpfile.js ├── index.html ├── js | ├── app.component.js | └── boot.js ├── source | ├── app.component.ts | └── boot.ts ├── node_modules ├── module 1 …
ksharifbd
  • 5,102
  • 2
  • 18
  • 23