How to use gulp

Comprehensive gulp code examples:

How to use gulp.sourcemaps:

213
214
215
216
217
218
219
220
221
222
223
          argv.verbose, argv.debug, argv.strict))
      .pipe(gulp.sourcemaps.mapSources(function(sourcePath, file) {
        return sourcePath.replace(/-/g, '/');
      }))
      .pipe(
          gulp.sourcemaps.write('.', {includeContent: false, sourceRoot: './'}))
      .pipe(gulp.dest('./'));
};


/**

How to use gulp.registry:

139
140
141
142
143
144
145
146
147
148
149
150
            'lint'
        )
    )
);


const BUILD_TASK = noBuild ? () => Promise.resolve() : gulp.registry().get('build');


// Test
gulp.step('test-server-run', () => {
    return gulp.src('./test/server/**/*-test.js', { read: false })

How to use gulp.emit:

18
19
20
21
22
23
24
25
26
27
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;
  }
  const start = process.hrtime();
  gulp.emit('task_start', metadata);

How to use gulp.replace:

40
41
42
43
44
45
46
47
48
49
50
function stripApacheLicense() {
  // Strip out Google's and MIT's Apache licences.
  // Closure Compiler preserves dozens of Apache licences in the Blockly code.
  // Remove these if they belong to Google or MIT.
  // MIT's permission to do this is logged in Blockly issue #2412.
  return gulp.replace(new RegExp(licenseRegex, "g"), '\n\n\n\n');
  // Replace with the same number of lines so that source-maps are not affected.
}


/**

How to use gulp.start:

176
177
178
179
180
181
182
183
184
  // create dist directories
  fs.mkdirSync('dist')
  fs.mkdirSync('dist/maps')

  // run the tasks
  gulp.start('html', 'sass', 'js', 'images', 'fonts', 'videos', 'favicon')
})

gulp.task('default', ['build', 'server', 'watch'])

How to use gulp.task:

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)

How to use gulp.dest:

112
113
114
115
116
117
118
119
120
121
122
123
    .pipe(gulp.dest(`${config.dataDir}/filter/gtfs`))
}))


gulp.task('copyRouterConfig', function () {
  return gulp.src(['router-*/**']).pipe(
    gulp.dest(config.dataDir))
})


// Run one of more filter runs on gtfs files(based on config) and moves files to
// directory 'ready'

How to use gulp.parallel:

93
94
95
96
97
98
const jsState1 = gulp.series(jsLint);
const jsState3 = gulp.parallel(jsLibs, jsApp, jsAdmin);
const jsState2 = gulp.series(jsClean, webpack, jsState3, jsMin);

exports.jsLint = jsLint;
exports.js = gulp.parallel(jsState1, jsState2);

How to use gulp.watch:

218
219
220
221
222
223
224
225
226
227
    'sample/widgets/*/*.html',
    'sample/widgets/*/src/*.js',
    'sample/widgets/*/src/*.css',
    'sample/widgets/*/src/*.html'
  ];
  gulp.watch(paths, ['reload']);
});

gulp.task('webserver', ['install-widgets'], function(){
  connect.server({

How to use gulp.series:

86
87
88
89
90
91
92
93
94
95

/**
 * install packages
 */
function install() {
  return gulp.series(async () => {
    const demoDist = config.demoDist
    const demoPackageJsonPath = path.join(demoDist, 'package.json')
    const packageJson = _.readJson(path.resolve(__dirname, '../package.json'))
    const dependencies = packageJson.dependencies || {}

How to use gulp.src:

152
153
154
155
156
157
158
159
160
161
gulp.task('sample-templates', function(){
  var opts = {
    root: 'partials',
    module: 'sample'
  };
  return gulp.src('sample/partials/*.html')
             .pipe($.minifyHtml(minifyHtmlOptions))
             .pipe($.angularTemplatecache('samples.js', opts))
             .pipe(gulp.dest('.tmp'));
});