How to use the src function from gulp

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

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'));
});
fork icon446
star icon950
watch icon96

+ 27 other calls in file

21
22
23
24
25
26
27
28
29
30
  return del('lib/**');
}


function build() {
  return gulp.src('src/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(babel())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('lib'))
fork icon558
star icon2
watch icon0

+ 5 other calls in file

14
15
16
17
18
19
20
21
22
23
var plugin1 = require('gulp-plugin1');
var plugin2 = require('gulp-plugin2');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('javascript', function() {
  gulp.src('src/**/*.js')
    .pipe(sourcemaps.init())
      .pipe(plugin1())
      .pipe(plugin2())
    .pipe(sourcemaps.write())
fork icon1
star icon1
watch icon3

+ 53 other calls in file

31
32
33
34
35
36
37
38
39
40
                })))
                .pipe(tslint.report());
});

gulp.task('compile:src', function (done) {
        gulp.src([
                config.paths.project.root + '/src/**/*.sql',
                config.paths.project.root + '/src/**/*.svg',
                config.paths.project.root + '/src/**/*.html'
        ]).pipe(gulp.dest('out/src/'));
fork icon869
star icon0
watch icon1

+ 9 other calls in file

50
51
52
53
54
55
56
57
58
59
      'node_modules/jspdf/dist/jspdf.umd.min.js',
      'node_modules/json-digger/dist/json-digger.js'
    ])
    .pipe(gulp.dest(paths.demoJSFolder));

  var cssFiles = gulp.src(paths.srcCSS)
    .pipe(gulp.dest(paths.demoCSSFolder));

  return merge(jsFiles, cssFiles);
}));
fork icon758
star icon0
watch icon150

+ 17 other calls in file

45
46
47
48
49
50
51
52
53
54
  }
}

TASK_CONFIG.stylesheets.configured = true

return gulp.src(paths.src)
  .pipe(gulpif(!global.production, sourcemaps.init()))
  .pipe(gulpif(preprocess, sass(TASK_CONFIG.stylesheets.sass)))
  .on('error', handleErrors)
  .pipe(postcss(TASK_CONFIG.stylesheets.postcss.plugins, TASK_CONFIG.stylesheets.postcss.options))
fork icon712
star icon0
watch icon149

+ 3 other calls in file

292
293
294
295
296
297
298
299
300
301
blocklyDemoConfig.pageRoot = `${baseDir}/${exampleDir}`;
const pageRegex = /.*\.(html|htm|md)$/i;
const pages = blocklyDemoConfig.files.filter((f) => pageRegex.test(f));
const assets = blocklyDemoConfig.files.filter((f) => !pageRegex.test(f));

let stream = gulp.src(
    pages.map((f) => path.join(baseDir, exampleDir, f)),
    {base: baseDir, allowEmpty: true})
    .pipe(gulp.header(buildFrontMatter(blocklyDemoConfig)));
if (assets.length) {
fork icon468
star icon632
watch icon0

24
25
26
27
28
29
30
31
32
33
gulp.task('watch', function() {
  gulp.watch(Paths.SCSS, gulp.series('compile-scss'));
});

gulp.task('open', function() {
  gulp.src('index.html')
    .pipe(open());
});

gulp.task('open-app', gulp.parallel('open', 'watch'));
fork icon449
star icon0
watch icon45

+ 7 other calls in file

61
62
63
64
65
66
67
68
69
70

For example:

```javascript
gulp.task('sass', function () {
 return gulp.src('./sass/**/*.scss')
   .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
   .pipe(gulp.dest('./css'));
});
```
fork icon391
star icon0
watch icon2

+ 19 other calls in file

64
65
66
67
68
69
70
71
72
73

// 压缩 css 文件
// 在命令行使用 gulp css 启动此任务
gulp.task('css', function () {
    // 1. 找到文件
    return gulp.src('css/*.css')
    // 2. 压缩文件
        .pipe(minifyCSS())
    // 3. 另存为压缩文件
        .pipe(gulp.dest('dist/css'))
fork icon372
star icon0
watch icon354

+ 11 other calls in file

166
167
168
169
170
171
172
173
174

```js
var uglify = require('gulp-uglify')

gulp.task('uglifyjs', function () {
    gulp.src('src/js/**/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'))
})
fork icon372
star icon0
watch icon354

+ 5 other calls in file

63
64
65
66
67
68
69
70
71
72
                .pipe(rename('script.js'))
                .pipe(gulp.dest('./docs/assets/js/'));
});

gulp.task('buildDoc:css', function() {
        return gulp.src('./docs/assets/css/scss/index.scss')
                .pipe(gulpif(isSourcemaps, sourcemaps.init({ loadMaps: true })))
                .pipe(sass({ outputStyle: 'compressed' })
                        .on('error', sass.logError)
                )
fork icon262
star icon0
watch icon95

+ 19 other calls in file

61
62
63
64
65
66
67
68
69
70
  }
  return stream;
})

gulp.task('clean', function () {
  return gulp.src('dist/*').pipe(
    clean({
      force: true,
    }),
  )
fork icon187
star icon0
watch icon43

+ 7 other calls in file

65
66
67
68
69
70
71
72
73
74
}

const distDir = path.dirname(dist);
const distBasename = path.basename(dist);

gulp.src(src)
    .pipe(sourcemaps.init())
    .pipe(insert.prepend(prependContent))
    .pipe(postcss(plugins))
    .pipe(rename(distBasename))
fork icon163
star icon0
watch icon79

+ 14 other calls in file

23
24
25
26
27
28
29
30
31
32
The above will compile `src/entry.js` into assets with webpack into `dist/` with the output filename of `[hash].js` (webpack generated hash of the build).

You can pass webpack options in with the first argument, including `watch` which will greatly decrease compilation times:

```js
return gulp.src('src/entry.js')
  .pipe(webpack({
    watch: true,
    module: {
      rules: [
fork icon128
star icon0
watch icon29

+ 43 other calls in file

20
21
22
23
24
25
26
27
28
29
 * get wxss stream
 */
function wxss(wxssFileList) {
  if (!wxssFileList.length) return false

  return gulp.src(wxssFileList, {cwd: srcPath, base: srcPath})
    .pipe(gulpif(wxssConfig.less && wxssConfig.sourcemap, sourcemaps.init()))
    .pipe(gulpif(wxssConfig.less, less({paths: [srcPath]})))
    .pipe(rename({extname: '.wxss'}))
    .pipe(gulpif(wxssConfig.less && wxssConfig.sourcemap, sourcemaps.write('./')))
fork icon67
star icon602
watch icon15

+ 7 other calls in file

305
306
307
308
309
310
311
312
313
314

```javascript
gulp.task('speak', function() {
    var message = 'Tea...Earl Grey...Hot';

    gulp.src('').pipe(shell('say ' + message));
});
```

If you wish to call this task from Elixir, use the `mix.task` method and pass the name of the task as the only argument to the method:
fork icon0
star icon290
watch icon40

+ 11 other calls in file

120
121
122
123
124
125
126
127
128
    .pipe(concat('vendor.js'))
    .pipe(gulp.dest('_build/assets/js'));
});

gulp.task('javascript:docs', function() {
  return gulp.src(CONFIG.JS_DOCS)
    .pipe(concat('docs.js'))
    .pipe(gulp.dest('_build/assets/js'));
});
fork icon0
star icon1
watch icon3

+ 9 other calls in file

158
159
160
161
162
163
164
165
166

const src = gulp.src(out + '/**', { base: '.' })
        .pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); }))
        .pipe(util.setExecutableBit(['**/*.sh']));

const extensions = gulp.src('.build/extensions/**', { base: '.build', dot: true });

const sources = es.merge(src, extensions)
        .pipe(filter(['**', '!**/*.js.map'], { dot: true }));
fork icon0
star icon2
watch icon0

+ 15 other calls in file

95
96
97
98
99
100
101
102
103
104
})

// images

gulp.task('images', () => {
  return gulp.src('src/images/**/*.{gif,jpg,png,svg}')
    .pipe(plumber({ errorHandler: onError }))
    .pipe(changed('dist/images'))
    .pipe(imagemin({ progressive: true, interlaced: true }))
    .pipe(gulp.dest('dist/images'))
fork icon209
star icon0
watch icon73

+ 7 other calls in file