How to use the task function from gulp

Find comprehensive JavaScript gulp.task code examples handpicked from public code repositorys.

170
171
172
173
174
175
176
177
178
179
})

/**
 * write json to the dist folder
 */
gulp.task(`${id}-component-json`, done => {
  const jsonFileList = this.componentListMap.jsonFileList

  if (jsonFileList && jsonFileList.length) {
    return copy(this.componentListMap.jsonFileList)
fork icon67
star icon602
watch icon15

+ 15 other calls in file

173
174
175
176
177
178
179
180
181
182

By default a comment containing / referencing the source map is added. Set this to `false` to disable the comment (e.g. if you want to load the source maps by header).

Example:
```javascript
gulp.task('javascript', function() {
  var stream = gulp.src('src/**/*.js')
    .pipe(sourcemaps.init())
      .pipe(plugin1())
      .pipe(plugin2())
fork icon1
star icon1
watch icon3

+ 17 other calls in file

341
342
343
344
345
346
347
348
349
350
var shell = require('gulp-shell');
var elixir = require('laravel-elixir');

elixir.extend('speak', function(message) {

    gulp.task('speak', function() {
        gulp.src('').pipe(shell('say ' + message));
    });

    return this.queueTask('speak');
fork icon0
star icon290
watch icon40

+ 5 other calls in file

77
78
79
80
81
82
83
84
85
gulp.task('auto', function () {
    // 监听文件修改,当文件被修改则执行 css 任务
    return gulp.watch('css/*.css', gulp.series(['css']))
});

// 使用 gulp.task('default') 定义默认任务
// 在命令行使用 gulp 启动 css 任务和 auto 任务
gulp.task('default', gulp.series(['css', 'auto']))
```
fork icon372
star icon0
watch icon354

+ 11 other calls in file

121
122
123
124
125
126
127
128
129
130
    dest: ''
  }
]

others.forEach(object => {
  gulp.task(object.name, () => {
    return gulp.src('src' + object.src)
      .pipe(plumber({ errorHandler: onError }))
      .pipe(gulp.dest('dist' + object.dest))
  })
fork icon209
star icon0
watch icon73

8
9
10
11
12
13
14
15
16
17
18
19


// Tell gulp to use the tasks just loaded
gulp.registry(hub);


gulp.task('build', gulp.series(gulp.parallel('other', 'webpack:dist')));
// gulp.task('test', gulp.series('karma:single-run'));
// gulp.task('test:auto', gulp.series('karma:auto-run'));
gulp.task('serve', gulp.series('webpack:watch', 'watch', 'browsersync'));
gulp.task('serve:dist', gulp.series('default', 'browsersync:dist'));
gulp.task('default', gulp.series('clean', 'build'));
fork icon1
star icon7
watch icon0

148
149
150
151
152
153
154
155
156
157
158
Object.entries(build.css).forEach(([filename, entry]) => {
  const { dist, src } = entry;
  const name = `css:${filename}`;
  tasks.css.push(name);


  gulp.task(name, () =>
    gulp
      .src(src)
      .pipe(plumber())
      .pipe(sass())
fork icon0
star icon0
watch icon1

+ 11 other calls in file

16
17
18
19
20
21
22
23
24
25
26
program.parse(process.argv);


function runTask(toRun) {
  const metadata = { task: toRun };
  // Gulp >= 4.0.0 (doesn't support events)
  const taskInstance = gulp.task(toRun);
  if (taskInstance === undefined) {
    gulp.emit('task_not_found', metadata);
    return;
  }
fork icon0
star icon0
watch icon2

79
80
81
82
83
84
85
86
87
88
89
90


// Task: Build CSS and run sass-lint to notify of any errors (but not fix them).
gulp.task('build-css', gulp.series('compile-css', 'lint-scss'));


// JS
// gulp.task('build-js', function() {
//   gulp.src(['./js/global.js'])
//     .pipe(concat('global.js'))
//     .pipe(minifyjs())
//     .pipe(uglify())
fork icon0
star icon0
watch icon0

43
44
45
46
47
48
49
50
51
52
53
            .pipe(gulpIf(isDevelopment, sourcemaps.write()))
            .pipe(gulpIf(isProduction, cleanCSS()))
            .pipe(gulp.dest('build/css'));
    });
//PUG
    gulp.task('pug', function(){


        return gulp.src('front/pug/tempPages/*.pug')
            .pipe(plumber({
                errorHandler: notify.onError()
fork icon0
star icon0
watch icon0

+ 10 other calls in file

64
65
66
67
68
69
70
71
72
73
74
75
            suffix: '.min'
        }))
        .pipe(gulp.dest(dest_dir));
};


// gulp.task('js', function() {
//     compileJS(false);
// });


gulp.task('css', function() {
fork icon0
star icon0
watch icon0

44
45
46
47
48
49
50
51
52
53
54
var assetsDir = 'assets/',
	outputDir = 'dist/',
	buildDir = 'build/';


//--------------------------------------webp
// gulp.task('imgWebp', function () {
// 	return gulp
// 		.src(assetsDir + 'i/**/*')
// 		.pipe(
// 			webp({
fork icon0
star icon0
watch icon0

+ 3 other calls in file

220
221
222
223
224
225
226
227
228
229
230
231
        .pipe(gulpif('*.js', uglify()))
        .pipe(gulpif('*.css', cssnano({ svgo: false })))
        .pipe(gulp.dest(paths.dist.base.dir));
});


// gulp.task('build', gulp.series(gulp.parallel('clean:tmp', 'clean:packageLock', 'clean:dist', 'copy:all', 'copy:libs'), 'scss', 'html'));
gulp.task('build', gulp.series(gulp.parallel('clean:packageLock', 'clean:dist', 'copy:all', 'copy:libs'), 'scss', 'html', 'js', 'jsPages'));


// gulp.task('default', gulp.series(gulp.parallel('fileinclude', 'scss'), gulp.parallel('browsersync', 'watch')));
gulp.task('default', gulp.series(gulp.parallel('clean:packageLock', 'clean:dist', 'copy:all', 'copy:libs', 'fileinclude', 'scss', 'js', 'jsPages', 'html'), gulp.parallel('browsersync', 'watch')));
fork icon0
star icon0
watch icon0

180
181
182
183
184
185
186
187
188
                        .pipe(gulp.dest(out));
        }));

        // Tasks
        gulp.task(compileTask);
        gulp.task(watchTask);

        return { compileTask, watchTask, compileBuildTask };
});
fork icon0
star icon0
watch icon6

+ 3 other calls in file

140
141
142
143
144
145
146
147
148
149
gulp.task(minifyVSCodeTask);

const core = task.define('core-ci', task.series(
        gulp.task('compile-build'),
        task.parallel(
                gulp.task('minify-vscode'),
                gulp.task('minify-vscode-reh'),
                gulp.task('minify-vscode-reh-web'),
        )
));
fork icon0
star icon0
watch icon0

+ 15 other calls in file

147
148
149
150
151
152
153
154
155
156
});

const defaultNodeTask = gulp.task(`node-${process.platform}-${process.arch}`);

if (defaultNodeTask) {
        gulp.task(task.define('node', defaultNodeTask));
}

function nodejs(platform, arch) {
        const { remote } = require('./lib/gulpRemoteSource');
fork icon0
star icon0
watch icon0

+ 5 other calls in file

189
190
191
192
193
194
195
196
197
198
                .pipe(pipeline())
                .pipe(gulp.dest(out));
}));

// Tasks
gulp.task(transpileTask);
gulp.task(compileTask);
gulp.task(watchTask);

return { transpileTask, compileTask, watchTask, compileBuildTask };
fork icon0
star icon0
watch icon1

+ 5 other calls in file