Content deleted Content added
organisation changes |
Stevebroshar (talk | contribs) It's a build tool; not a framework |
||
(94 intermediate revisions by 59 users not shown) | |||
Line 1:
{{Short description|Server-side JavaScript build tool}}
{{lowercase title}}
{{multiple issues|
{{How-to|date=October 2016}}
{{context|date=January 2017}}
}}
{{Infobox software
| name = gulp
| logo = Gulp.js Logo.svg
| logo caption =
| logo alt =
| logo size = 100px
| collapsible =
| screenshot = <!-- Image name is enough -->
| screenshot size =
| screenshot alt =
| caption =
| other_names =
| author = Eric Schoffstall<ref name=":0">{{Cite book|title=Developing a Gulp Edge|publisher=Bleeding Edge Press|year=2014|isbn=978-1-939902-14-6|edition=1st|author1=Jed Mao |author2=Maximilian Schmitt |author3=Tomasz Stryjewski |author4=Cary Country Holt |author5=William Lubelski }}</ref>
| developer = Blaine Bublitz, Eric Schoffstall
| released = {{Start date and age|2013|09|26|df=yes}}<ref>{{cite web | url=https://libraries.io/npm/gulp/versions | access-date=2020-12-31 | title=Release Date of Version 1.0.0}}</ref><!-- As per template guideline, this is the release date of version 1.0.0 -->
| ver layout =
| discontinued =
| latest release version = 5.0.0
| latest_release_date = {{Start date and age|2024|03|29|df=yes}}<ref name="latest-releases">{{cite web | url=https://github.com/gulpjs/gulp/releases | access-date=2020-12-31 | title=Releases · gulpjs/gulp| website=[[GitHub]] }}</ref>
| latest preview version =
| latest preview date =
| repo = {{URL|https://github.com/gulpjs/gulp}}
| qid =
| programming language = [[JavaScript]] <!-- Node.js is NOT a language, it is a platform -->
| middleware =
| tools =
| engine =
| operating system = [[Linux]], [[macOS]], [[Windows]] <!-- As per template guideline, do not write "Cross-platform" here -->
| platform = [[Node.js]] <!-- As per template guideline, do not write "Cross-platform" here -->
| included with =
| replaces =
| replaced_by =
| service_name =
| size =
| standard =
| language =
| language count =
| language footnote =
| genre = [[Toolkit]]
| license = [[MIT License]]<ref>{{cite web | url=https://github.com/gulpjs/gulp/blob/master/LICENSE | title=LICENSE file on GitHub | website=[[GitHub]] | access-date=2020-12-31}}</ref><ref>{{cite web | url=https://www.npmjs.com/package/gulp | title=License field from gulp - npm | access-date=2020-12-31}}</ref>
| website =
| AsOf =
}}
'''gulp''' is an [[Open-source software|open-source]] [[JavaScript]] toolkit, used as a streaming [[build system]] (similar to a more package-focused [[Make (software)|Make]]) in [[front-end web development]].
It is a task runner built on [[Node.js]] and [[
gulp uses a code-over-configuration approach to define its tasks and relies on its small, single-
== Overview ==
gulp<ref>{{
==
Task-runners like gulp and [[Grunt (software)|Grunt]] are built on Node.js rather than [[Node Package Manager|npm]] because the basic npm scripts are inefficient when executing multiple tasks.
Even though some developers prefer [[Node Package Manager|npm]] scripts because they can be simple and easy to implement, there are numerous ways where gulp and Grunt seem to have an advantage over each other, and the default provided scripts.<ref name="gulpjs/gulp">{{cite web|url=https://github.com/gulpjs/gulp/blob/master/docs/CLI.md|title=gulpjs/gulp|website=GitHub|access-date=2016-09-23}}</ref> Grunt runs tasks by transforming files and saves them as new ones in temporary folders, and the output of one task is taken as input for another and so on until the output reaches the destination folder. This involves a lot of [[I/O]] calls and the creation of many temporary files. Whereas gulp streams through the file system do not require any of these temporary locations, decreasing the number of I/O calls thus, improving performance.<ref>{{cite web|url=https://css-tricks.com/gulp-for-beginners/ |title=Gulp for Beginners |publisher=CSS-Tricks |date=2015-09-01 |access-date=2016-12-14}}</ref> Grunt uses configuration files to perform tasks, whereas gulp requires its build file to be coded. In Grunt, each plugin needs to be configured to match its input ___location to the previous plugin's output. In gulp, the plugins are automatically pipe-lined.<ref name="github.com"/>
== Operation ==
The gulp tasks are run from a [[command-line interface]] (CLI)<ref name="gulpjs/gulp"/> shell and require two files, <code>package.json</code>, which is used to list the various plugins for gulp, and <code>gulpfile.js</code> (or simply <code>gulpfile</code>), These, as per build tool convention, are often found in the root directory of the package's source code. The gulpfile contains most of the logic that gulp needs to run its build tasks. First, all the necessary modules are loaded and then tasks are defined in the gulpfile. All the necessary plugins specified in the gulpfile are listed in the devDependencies section of <code>package.json</code>.<ref name=":2">{{cite web|url=https://docs.npmjs.com/cli/install|title=install {{!}} npm Documentation|website=docs.npmjs.com|access-date=2016-09-22}}</ref> The default task runs by <code>$gulp</code>. Individual tasks can be defined by gulp.task and are run by <code>gulp <task> <othertask></code>.<ref name=":1">{{cite web|url=https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md|title=gulpjs/gulp|website=GitHub|access-date=2016-09-23}}</ref> Complex tasks are defined by chaining the plugins with the help of <code>.pipe()</code> operator.<ref name=":3" />
== Anatomy of gulpfile ==
gulpfile is the place where all the operations are defined in gulp. The basic anatomy of the gulpfile consists of required plugins included at the top, definition of the tasks and a default task at the end.<ref name="sitepoint.com">{{cite web|url=https://www.sitepoint.com/introduction-gulp-js/|title=An Introduction to Gulp.js - SitePoint|date=2014-02-10|language=en-US|access-date=2016-09-23}}</ref>
=== Plugins ===
Any installed plugin that is required to perform a task is to be added at the top of the gulpfile as a
//Adding dependencies
var gulp = require (
</syntaxhighlight>
Line 51 ⟶ 77:
The tasks can then be created. A gulp task is defined by ''gulp.task'' and takes the name of the task as the first parameter and a function as the second parameter.
The following example shows the creation of a gulp tasks. The first parameter ''
gulp.task('taskName', function () {
//do something
});
</syntaxhighlight>
Line 60 ⟶ 85:
Alternatively, a task that performs several predefined functions can be created. Those functions are passed as the second parameter in the form of an array. <syntaxhighlight lang="javascript">
function fn1 () {
// do something
}
function
//
}
// Task with array of function names
gulp.task
</syntaxhighlight>
=== Default task ===
The default task is to be defined at the end of the gulpfile. It can be run by the <code>gulp</code> command in the shell. In the case below, the default task does nothing.<ref name=":3" /> <syntaxhighlight lang
// Gulp default task
gulp.task
</syntaxhighlight>The default task is used in gulp to run any number of dependent sub tasks defined above in a sequential order automatically. gulp can also monitor source files and run an appropriate task when changes are made to the files. The sub tasks are to be mentioned as the elements of the array in the second parameter. The process can be triggered by simply running the default task by <code>gulp</code> command.<ref
== Example tasks ==
=== Image Task ===
The module definition can be at the beginning of <code>Gulpfile.js</code> like so:<syntaxhighlight lang="javascript">
var imagemin = require('gulp-imagemin');
</syntaxhighlight>
The subsequent image task optimizes images. <Code>
// Images task
gulp.task
return gulp.src
.pipe
.pipe
});
Line 100 ⟶ 123:
=== Scripts Task ===
In the following example, all JavaScript files from the directory ''
// Script task
gulp.task
return gulp.src
.pipe
.pipe
});
</syntaxhighlight>
=== Watch Task ===
The Watch-task serves to react to changes in files. In the following example, the tasks with the names ''scripts
// Rerun the task When a file changes
gulp.task
gulp.watch
gulp.watch
cb();
});
</syntaxhighlight>
Furthermore, it is possible to accomplish an update of the browser content using the Watch-tasks
==See also==
* [[Grunt (software)]]
* [[Browserify]]
==
{{Reflist|30em}}
==Literature==
*{{Cite book|title=Developing a Gulp Edge|publisher=Bleeding Edge Press|year=2014|isbn=978-1-939902-14-6|edition=1st|author1=Jed Mao |author2=Maximilian Schmitt |author3=Tomasz Stryjewski |author4=Cary Country Holt |author5=William Lubelski }}
*{{Cite book| author=Den Odell | title=Pro JavaScript Development Coding, Capabilities, and Tooling | publisher=Apress |year=2014 |chapter=Build Tools and Automation |isbn=978-1-4302-6268-8}}
*{{Cite book|title=Getting Started with Gulp|last=Maynard|first=Travis|publisher=Packt Publishing Ltd|year=2015|isbn=9781784393472
==
*
*
[[Category:JavaScript programming tools]]
|