How to use the dest function from gulp

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

gulp.dest is a method in the Gulp JavaScript toolkit that writes files to a destination directory.

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'
fork icon21
star icon11
watch icon18

336
337
338
339
340
341
342
343
344
345
346
    [
      gulp.src(['README.md', 'LICENSE', 'CHANGELOG.md',
        `${config.buildDir}/lib-es5/**/*.d.ts`,
        `${config.buildDir}/lib-es5/**/*.metadata.json`]),
      gulpFile('package.json', JSON.stringify(targetPkgJson, null, 2)),
      gulp.dest(config.outputDir)
    ], cb);
});


// Bundles the library as UMD/FESM bundles using RollupJS
fork icon3
star icon17
watch icon1

+ 4 other calls in file

How does gulp.dest work?

gulp.dest is a method in the Gulp JavaScript toolkit that writes files to a destination directory. When you call gulp.dest, you specify a destination directory where you want to write the files. gulp.dest then returns a stream that you can pipe files to. When a file is piped to gulp.dest, the method writes the file to the specified destination directory, creating any necessary directories in the process. If the file already exists in the destination directory, gulp.dest will overwrite it with the new file. Note that gulp.dest does not modify the contents of the files that are piped to it. If you need to modify the contents of a file, you should use other Gulp methods, such as gulp.src and gulp.pipe. By using gulp.dest, you can easily write files to a destination directory as part of your Gulp workflow, allowing you to build and process files in a flexible and modular way.

47
48
49
50
51
52
53
54
55
      ? `metamask-BETA-${platform}-${betaVersion}`
      : `metamask-${platform}-${version}`;
    await pump(
      gulp.src(`dist/${platform}/**`),
      gulpZip(`${path}.zip`),
      gulp.dest('builds'),
    );
  };
}
fork icon1
star icon0
watch icon1

+ 4 other calls in file

71
72
73
74
75
76
77
78
79
80
81
82
	];
}




function minifyComponents(cb) {
	pump([src(paths.components), ...minifyJS(), rename({ suffix: '.min' }), dest('components')], cb);
}
function minifyPlugins(cb) {
	pump([src(paths.plugins), ...minifyJS(), rename({ suffix: '.min' }), dest('plugins')], cb);
}
fork icon0
star icon1
watch icon2

+ 9 other calls in file

Ai Example

1
2
3
4
5
6
const gulp = require("gulp");

// Define a task to copy files to a destination directory
gulp.task("copy-files", function () {
  return gulp.src("src/**/*").pipe(gulp.dest("dist"));
});

In this example, we start by requiring the gulp module and defining a task called copy-files that copies files to a destination directory. We use gulp.src to specify the source files that we want to copy. In this case, we use a glob pattern (src/**/*) to match all files and directories in the src directory. We then pipe the source files to gulp.dest, passing in the dist directory as the destination. gulp.dest writes the files to the destination directory and returns a stream, which we can then use to continue our Gulp workflow. Note that in this example, we are only using gulp.dest to write files to a destination directory. If you need to modify the contents of the files that are piped to gulp.dest, you should use other Gulp methods, such as gulp-rename or gulp-replace. By using gulp.dest, you can easily write files to a destination directory as part of your Gulp workflow, allowing you to build and process files in a flexible and modular way.

133
134
135
136
137
138
139
140
141
// webview / html
function(){
    if( isDebug ){
        return gulp.src( './src/html/' + htmlSourceFileName )
                   .pipe( gulpHTMLClean() )
                   .pipe( gulp.dest( tempDir ) );
    } else {
        const js  = fs.readFileSync( tempDir + '/' + javascriptFileName ).toString();
        const css = fs.readFileSync( tempDir + '/' + scssFilename.replace( 'scss', 'css' ) ).toString().replace('@charset "UTF-8";', '');
fork icon0
star icon0
watch icon1

+ 3 other calls in file

32
33
34
35
36
37
38
39
40
41
42
                                            target === `ts`       ? createTypeScriptPackageJson(target, format)
                                                                  : createScopedPackageJSON(target, format),
                                            2);
    return Observable.forkJoin(
      observableFromStreams(gulp.src(metadataFiles), gulp.dest(out)), // copy metadata files
      observableFromStreams(gulp.src(`package.json`), jsonTransform, gulp.dest(out)) // write packageJSONs
    ).publish(new ReplaySubject()).refCount();
}))({});


module.exports = packageTask;
fork icon0
star icon0
watch icon1

77
78
79
80
81
82
83
84
85
86
            closureCompiler(createClosureArgs(entry_point, externs, target), {
                platform: ['native', 'java', 'javascript']
            }),
            // rename the sourcemaps from *.js.map files to *.min.js.map
            sourcemaps.write(`.`, { mapFile: (mapPath) => mapPath.replace(`.js.map`, `.${target}.min.js.map`) }),
            gulp.dest(out)
        );
    }
}))({});

fork icon0
star icon0
watch icon1

329
330
331
332
333
334
335
336
337
338
339
		}))
		.pipe($.eslint({
			fix: argv.fix,
		}))
		.pipe($.eslint.format())
		.pipe($.if((file) => file.eslint && file.eslint.fixed, gulp.dest('.')));
});


gulp.task('validate:html', () => {
	return gulp.src('build/**/*.html')
fork icon0
star icon0
watch icon1

+ 3 other calls in file

85
86
87
88
89
90
91
92
93
94
95
      }
    })
    .pipe(gulp.dest('dist'))
    .pipe(gulpif(!skipMinification, uglify()))
    .pipe(gulpif(!skipMinification, rename('sweetalert2.min.js')))
    .pipe(gulpif(!skipMinification, gulp.dest('dist')))
})


gulp.task('build:styles', () => {
  const result = sass.renderSync({ file: 'src/sweetalert2.scss' })
fork icon0
star icon0
watch icon1

755
756
757
758
759
760
761
762
763
764
  }
}

return merge([
  createStringSource("locale.properties", viewerOutput).pipe(
    gulp.dest(VIEWER_LOCALE_OUTPUT)
  ),
  gulp
    .src(L10N_DIR + "/{" + locales.join(",") + "}/viewer.properties", {
      base: L10N_DIR,
fork icon0
star icon0
watch icon2

+ 27 other calls in file

1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
}).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")),
gulp
  .src(MOZCENTRAL_WEB_FILES, { base: "web/" })
  .pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")),
createCMapBundle().pipe(
  gulp.dest(MOZCENTRAL_CONTENT_DIR + "web/cmaps")
),
createStandardFontBundle().pipe(
  gulp.dest(MOZCENTRAL_CONTENT_DIR + "web/standard_fonts")
),
fork icon0
star icon0
watch icon0

+ 119 other calls in file

189
190
191
192
193
194
195
196
197
198
.pipe($.if(process.env.NODE_ENV === 'dev', $.plumber({ errorHandler })))
.pipe(sass(gulpConfig.css.sass))
.pipe($.autoprefixer())
.pipe($.change(generateCSSComments))
.pipe($.header(getHeaderComment()))
.pipe($.if(process.env.NODE_ENV !== 'production', gulp.dest(gulpConfig.css.to)))
.pipe(browserSync.stream())
.pipe($.if(process.env.NODE_ENV !== 'dev', $.cleanCss()))
.pipe($.rename({
    extname: '.min.css',
fork icon0
star icon0
watch icon1

+ 9 other calls in file

66
67
68
69
70
71
72
73
74
75
76
      }
    })
    .pipe(gulp.dest('dist'))
    .pipe($.if(!skipMinification, $.uglify()))
    .pipe($.if(!skipMinification, $.rename('sweetalert2.min.js')))
    .pipe($.if(!skipMinification, gulp.dest('dist')))
})


gulp.task('build:styles', () => {
  return gulp.src('src/sweetalert2.scss')
fork icon0
star icon0
watch icon1

75
76
77
78
79
80
81
82
83
84
          configFile: "./.eslintrc.json",
          fix: true
        })
      )
      .pipe(eslint.format())
      .pipe(gulpIf(isFixed, gulp.dest("./")))
      // uncomment to stop on error
      .pipe(eslint.failAfterError())
  );
}
fork icon0
star icon0
watch icon2

+ 3 other calls in file

24
25
26
27
28
29
30
31
32
33
34
35
        .pipe(sourcemaps.init())
        .pipe(sass())
        .pipe(postcss([autoprefixer(), cssnano()]))
        // .pipe(postcss([autoprefixer()]))
        .pipe(sourcemaps.write('.'))
        .pipe( dest('public/build/css') );
}




function javascript() {
fork icon0
star icon0
watch icon0

166
167
168
169
170
171
172
173
174
175
  ).pipe(dest(conf.distPath));
};
// Copy task for form validation plugin as premium plugin don't have npm package
const buildPluginCopyTask = function () {
  return src(srcGlob('libs/formvalidation/dist/js/**/*.js')).pipe(
    dest(`${conf.distPath}/libs/formvalidation/dist/js/`)
  );
};

const buildAllTask = series(buildCssTask, buildJsTask, buildFontsTask, buildCopyTask, buildPluginCopyTask);
fork icon0
star icon0
watch icon0

50
51
52
53
54
55
56
57
58
59
            easyimport,
            colorFunction(),
            autoprefixer(),
            cssnano()
        ]),
        dest('assets/built/', {sourcemaps: '.'}),
        livereload()
    ], handleError(done));
}

fork icon0
star icon0
watch icon0

+ 2 other calls in file

46
47
48
49
50
51
52
53
54
55

### Errors

When `directory` is an empty string, throws an error with the message, "Invalid dest() folder argument. Please specify a non-empty string or a function."

When `directory` is not a string or function, throws an error with the message, "Invalid dest() folder argument. Please specify a non-empty string or a function."

When `directory` is a function that returns an empty string or `undefined`, emits an error with the message, "Invalid output folder".

### Options
fork icon0
star icon0
watch icon2

+ 29 other calls in file

54
55
56
57
58
59
60
61
62
63
      tsProject(ts.reporter.defaultReporter())
    );
    const writeSources = observableFromStreams(tsProject.src(), gulp.dest(out));
    const writeDTypes = observableFromStreams(dts, sourcemaps.write('./', { includeContent: false }), gulp.dest(out));
    const mapFile = tsProject.options.module === 5 ? esmMapFile : cjsMapFile;
    const writeJS = observableFromStreams(js, sourcemaps.write('./', { mapFile, includeContent: false }), gulp.dest(out));
    return Observable.forkJoin(writeSources, writeDTypes, writeJS);
}

function cjsMapFile(mapFilePath) { return mapFilePath; }
fork icon0
star icon0
watch icon2

+ 11 other calls in file

60
61
62
63
64
65
66
67
68
69
const tsProject = ts.createProject(tsconfigPath, { typescript: require(`typescript`), ...tsconfigOverrides});
const { stream: { js, dts } } = observableFromStreams(
  tsProject.src(), sourcemaps.init(),
  tsProject(ts.reporter.defaultReporter())
);
const writeSources = observableFromStreams(tsProject.src(), gulp.dest(path.join(out, 'src')));
const writeDTypes = observableFromStreams(dts, sourcemaps.write('./', { includeContent: false, sourceRoot: 'src' }), gulp.dest(out));
const mapFile = tsProject.options.module === 5 ? esmMapFile : cjsMapFile;
const writeJS = observableFromStreams(js, sourcemaps.write('./', { mapFile, includeContent: false }), gulp.dest(out));
return ObservableForkJoin([writeSources, writeDTypes, writeJS]);
fork icon0
star icon0
watch icon0

+ 5 other calls in file