Skip to content

Commit 31adf07

Browse files
janiceilenephated
authored andcommitted
Docs: Add "JavaScript and Gulpfiles" documentation
1 parent 21b6962 commit 31adf07

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!-- front-matter
2+
id: javascript-and-gulpfiles
3+
title: JavaScript and Gulpfiles
4+
hide_title: true
5+
sidebar_label: JavaScript and Gulpfiles
6+
-->
7+
8+
# JavaScript and Gulpfiles
9+
10+
Gulp allows you to use existing JavaScript knowledge to write gulpfiles or to use your experience with gulpfiles to write plain JavaScript. Although a few utilities are provided to simplify working with the filesystem and command line, everything else you write is pure JavaScript.
11+
12+
## Gulpfile explained
13+
14+
A gulpfile is a file in your project directory titled `gulpfile.js` (or capitalized as `Gulpfile.js`, like Makefile), that automatically loads when you run the `gulp` command. Within this file, you'll often see gulp APIs, like `src()`, `dest()`, `series()`, or `parallel()` but any vanilla JavaScript or Node modules can be used. Any exported functions will be registered into gulp's task system.
15+
16+
## Transpilation
17+
18+
You can write a gulpfile using a language that requires transpilation, like TypeScript or Babel, by changing the extension on your `gulpfile.js` to indicate the language and install the matching transpiler module.
19+
20+
* For TypeScript, rename to `gulpfile.ts` and install the [ts-node][ts-node-module] module.
21+
* For Babel, rename to `gulpfile.babel.js` and install the [@babel/register][babel-register-module] module.
22+
23+
For a more advanced dive into this topic and the full list of supported extensions, see our [gulpfile transpilation][gulpfile-transpilation-advanced] documentation.
24+
25+
## Splitting a gulpfile
26+
27+
Many users start by adding all logic to a gulpfile. If it ever grows too big, it can be refactored into separate files.
28+
29+
Each task can be split into its own file, then imported into your gulpfile for composition. Not only does this keep things organized, but it allows you to test each task independently or vary composition based on conditions.
30+
31+
Node's module resolution allows you to replace your `gulpfile.js` with a directory called `gulpfile` that contains an `index.js` file which is treated as a `gulpfile.js`. This directory could then contain your individual modules for tasks.
32+
33+
34+
[gulpfile-transpilation-advanced]: LINK_NEEDED
35+
[ts-node-module]: https://www.npmjs.com/package/ts-node
36+
[babel-register-module]: https://www.npmjs.com/package/@babel/register

0 commit comments

Comments
 (0)