fbpx
Wikipedia

gulp.js

gulp is an open-source JavaScript toolkit created by Eric Schoffstall[5] used as a streaming build system (similar to a more package-focused Make) in front-end web development.

sss
Original author(s)Eric Schoffstall
Developer(s)Blaine Bublitz, Eric Schoffstall
Initial release26 September 2013; 10 years ago (2013-09-26)[1]
Stable release
4.0.2 / 6 May 2019; 4 years ago (2019-05-06)[2]
Repositorygithub.com/gulpjs/gulp
Written inJavaScript
Operating systemLinux, macOS, Windows
PlatformNode.js
TypeToolkit
LicenseMIT License[3][4]
Websitegulpjs.com 

It is a task runner built on Node.js and npm, used for automation of time-consuming and repetitive tasks involved in web development like minification, concatenation, cache busting, unit testing, linting, optimization, etc.[6]

gulp uses a code-over-configuration approach to define its tasks and relies on its small, single-purpose plugins to carry them out. The gulp ecosystem includes more than 3500 such plugins.[7]

Overview Edit

gulp[8] is a build tool in JavaScript built on node streams. These streams facilitate the connection of file operations through pipelines.[9] gulp reads the file system and pipes the data at hand from one single-purposed plugin to another through the .pipe() operator, doing one task at a time. The original files are not affected until all the plugins are processed. It can be configured either to modify the original files or to create new ones. This grants the ability to perform complex tasks through linking its numerous plugins. The users can also write their own plugins to define their own tasks.[10] Unlike other task runners that run tasks by configuration, gulp requires knowledge of JavaScript and coding to define its tasks. gulp is a build system which means apart from running tasks, it is also capable of copying files from one location to another, compiling, deploying, creating notifications, unit testing, linting, etc.[5]

Need for a task runner Edit

Task-runners like gulp and Grunt are built on Node.js rather than npm because the basic npm scripts are inefficient when executing multiple tasks. Even though some developers prefer 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.[11] 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.[12] 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.[9]

Operation Edit

The gulp tasks are run from a command-line interface (CLI)[11] shell and require two files, package.json, which is used to list the various plugins for gulp, and gulpfile.js (or simply gulpfile), 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[13] The default task runs by $gulp. Individual tasks can be defined by gulp.task and are run by gulp <task> <othertask>.[14] Complex tasks are defined by chaining the plugins with the help of .pipe() operator.[15]

Anatomy of gulpfile Edit

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.[16]

Plugins Edit

Any installed plugin that is required to perform a task is to be added at the top of the gulpfile as a dependency in the following format.[14][15]

//Adding dependencies var gulp = require ('gulp'); 

Tasks Edit

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 taskName is mandatory and specifies the name by which the task in the shell can be executed.[17]

gulp.task('taskName', function () {  //do something }); 

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.

function fn1 () {  // do something } function fn2 () {  // do something } // Task with array of function names gulp.task('taskName', gulp.parallel(fn1, fn2)); 

Default task Edit

The default task is to be defined at the end of the gulpfile. It can be run by the gulp command in the shell. In the case below, the default task does nothing.[15]

// Gulp default task gulp.task('default', fn); 

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 gulp command.[16]

Example tasks Edit

Image Task Edit

The module definition can be at the beginning of Gulpfile.js like so:

var imagemin = require('gulp-imagemin'); 

The subsequent image task optimizes images. gulp.src() retrieves all the images with the extension .png, .gif or .jpg in the directory 'images-orig/'.

.pipe(imagemin()) channels the images found, through the optimization process and with .pipe(gulp.dest()) the optimized images are saved to the 'images/' folder. Without gulp.dest() the images would indeed be optimized, but are not stored.[18] Since the optimized images are stored to another folder, the original images remain unaltered.[15]

// Images task gulp.task('images', function () {  return gulp.src('images/*.{png,gif,jpg}')  .pipe(imagemin())  .pipe(gulp.dest('dist/images/')); }); 

Scripts Task Edit

In the following example, all JavaScript files from the directory scripts/ are optimized with .pipe(uglify()) and gulp.dest('scripts/') overwrites the original files with the output.[19] For this, one must first return to the required gulp-uglify plugin[20] on npm package installer and at the beginning of gulpfile, the module should be defined.

// Script task gulp.task('scripts', function () {  return gulp.src('scripts/*.js')  .pipe(uglify())  .pipe(gulp.dest('scripts/')); }); 

Watch Task Edit

The Watch-task serves to react to changes in files. In the following example, the tasks with the names scripts and images are called when any of JavaScript files or images change in the specified directories.[21]

// Rerun the task When a file changes gulp.task('watch', function (cb) {  gulp.watch('scripts/js/**', scripts);  gulp.watch('images/**', images);  cb(); }); 

Furthermore, it is possible to accomplish an update of the browser content using the Watch-tasks.[22] For this, there are numerous options and plugins.

See also Edit

References Edit

  1. ^ "Release Date of Version 1.0.0". Retrieved 2020-12-31.
  2. ^ "Releases · gulpjs/gulp". GitHub. Retrieved 2020-12-31.
  3. ^ "LICENSE file on GitHub". GitHub. Retrieved 2020-12-31.
  4. ^ "License field from gulp - npm". Retrieved 2020-12-31.
  5. ^ a b Jed Mao; Maximilian Schmitt; Tomasz Stryjewski; Cary Country Holt; William Lubelski (2014). Developing a Gulp Edge (1st ed.). Bleeding Edge Press. ISBN 978-1-939902-14-6.
  6. ^ "Building With Gulp – Smashing Magazine". Smashingmagazine.com. 11 June 2014. Retrieved 2016-12-14.
  7. ^ "gulp.js plugin registry". Gulpjs.com. Retrieved 2016-12-14.
  8. ^ "gulpjs/gulp". GitHub. Retrieved 2016-09-22.
  9. ^ a b "substack/stream-handbook: how to write node programs with streams". GitHub. Retrieved 2016-12-14.
  10. ^ "gulpjs/gulp". GitHub. Retrieved 2016-09-22.
  11. ^ a b "gulpjs/gulp". GitHub. Retrieved 2016-09-23.
  12. ^ "Gulp for Beginners". CSS-Tricks. 2015-09-01. Retrieved 2016-12-14.
  13. ^ "install | npm Documentation". docs.npmjs.com. Retrieved 2016-09-22.
  14. ^ a b "gulpjs/gulp". GitHub. Retrieved 2016-09-23.
  15. ^ a b c d Maynard, Travis (2015). Getting Started with Gulp. Packt Publishing Ltd. ISBN 9781784393472.
  16. ^ a b "An Introduction to Gulp.js - SitePoint". 2014-02-10. Retrieved 2016-09-23.
  17. ^ "gulp/API.md at 4.0 · gulpjs/gulp · GitHub". GitHub. 2016-05-12. Retrieved 2016-12-14.
  18. ^ "Durchstarten mit Gulp.js – Websites optimieren, Arbeitsabläufe automatisieren". Magazin.phlow.de. 2014-05-25. Retrieved 2016-12-14.
  19. ^ "Front-end Workflow mit Gulp - Liechtenecker". Liechtenecker.at. 2015-05-29. Retrieved 2016-12-14.
  20. ^ "gulp-uglify". Npmjs.com. Retrieved 2016-12-14.
  21. ^ "gulp-watch". Npmjs.com. Retrieved 2016-09-23.
  22. ^ "Browsersync + Gulp.js". Browsersync.io. Retrieved 2016-12-14.

Literature Edit

  • Jed Mao; Maximilian Schmitt; Tomasz Stryjewski; Cary Country Holt; William Lubelski (2014). Developing a Gulp Edge (1st ed.). Bleeding Edge Press. ISBN 978-1-939902-14-6.
  • Den Odell (2014). "Build Tools and Automation". Pro JavaScript Development Coding, Capabilities, and Tooling. Apress. ISBN 978-1-4302-6268-8.
  • Maynard, Travis (2015). Getting Started with Gulp. Packt Publishing Ltd. ISBN 9781784393472.

External links Edit

  • Official website  
  • gulp on GitHub

gulp, this, article, multiple, issues, please, help, improve, discuss, these, issues, talk, page, learn, when, remove, these, template, messages, this, article, contains, instructions, advice, content, purpose, wikipedia, present, facts, train, please, help, i. This article has multiple issues Please help improve it or discuss these issues on the talk page Learn how and when to remove these template messages This article contains instructions advice or how to content The purpose of Wikipedia is to present facts not to train Please help improve this article either by rewriting the how to content or by moving it to Wikiversity Wikibooks or Wikivoyage October 2016 This article provides insufficient context for those unfamiliar with the subject Please help improve the article by providing more context for the reader January 2017 Learn how and when to remove this template message Learn how and when to remove this template message gulp is an open source JavaScript toolkit created by Eric Schoffstall 5 used as a streaming build system similar to a more package focused Make in front end web development sssOriginal author s Eric SchoffstallDeveloper s Blaine Bublitz Eric SchoffstallInitial release26 September 2013 10 years ago 2013 09 26 1 Stable release4 0 2 6 May 2019 4 years ago 2019 05 06 2 Repositorygithub wbr com wbr gulpjs wbr gulpWritten inJavaScriptOperating systemLinux macOS WindowsPlatformNode jsTypeToolkitLicenseMIT License 3 4 Websitegulpjs wbr com It is a task runner built on Node js and npm used for automation of time consuming and repetitive tasks involved in web development like minification concatenation cache busting unit testing linting optimization etc 6 gulp uses a code over configuration approach to define its tasks and relies on its small single purpose plugins to carry them out The gulp ecosystem includes more than 3500 such plugins 7 Contents 1 Overview 2 Need for a task runner 3 Operation 4 Anatomy of gulpfile 4 1 Plugins 4 2 Tasks 4 3 Default task 5 Example tasks 5 1 Image Task 5 2 Scripts Task 5 3 Watch Task 6 See also 7 References 8 Literature 9 External linksOverview Editgulp 8 is a build tool in JavaScript built on node streams These streams facilitate the connection of file operations through pipelines 9 gulp reads the file system and pipes the data at hand from one single purposed plugin to another through the pipe operator doing one task at a time The original files are not affected until all the plugins are processed It can be configured either to modify the original files or to create new ones This grants the ability to perform complex tasks through linking its numerous plugins The users can also write their own plugins to define their own tasks 10 Unlike other task runners that run tasks by configuration gulp requires knowledge of JavaScript and coding to define its tasks gulp is a build system which means apart from running tasks it is also capable of copying files from one location to another compiling deploying creating notifications unit testing linting etc 5 Need for a task runner EditTask runners like gulp and Grunt are built on Node js rather than npm because the basic npm scripts are inefficient when executing multiple tasks Even though some developers prefer 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 11 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 12 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 9 Operation EditThe gulp tasks are run from a command line interface CLI 11 shell and require two files package json which is used to list the various plugins for gulp and gulpfile js or simply gulpfile 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 13 The default task runs by gulp Individual tasks can be defined by gulp task and are run by gulp lt task gt lt othertask gt 14 Complex tasks are defined by chaining the plugins with the help of pipe operator 15 Anatomy of gulpfile Editgulpfile 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 16 Plugins EditAny installed plugin that is required to perform a task is to be added at the top of the gulpfile as a dependency in the following format 14 15 Adding dependencies var gulp require gulp Tasks Edit 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 taskName is mandatory and specifies the name by which the task in the shell can be executed 17 gulp task taskName function do something 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 function fn1 do something function fn2 do something Task with array of function names gulp task taskName gulp parallel fn1 fn2 Default task EditThe default task is to be defined at the end of the gulpfile It can be run by the gulp command in the shell In the case below the default task does nothing 15 Gulp default task gulp task default fn 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 gulp command 16 Example tasks EditImage Task EditThe module definition can be at the beginning of Gulpfile js like so var imagemin require gulp imagemin The subsequent image task optimizes images gulp src retrieves all the images with the extension png gif or jpg in the directory images orig pipe imagemin channels the images found through the optimization process and with pipe gulp dest the optimized images are saved to the images folder Without gulp dest the images would indeed be optimized but are not stored 18 Since the optimized images are stored to another folder the original images remain unaltered 15 Images task gulp task images function return gulp src images png gif jpg pipe imagemin pipe gulp dest dist images Scripts Task EditIn the following example all JavaScript files from the directory scripts are optimized with pipe uglify and gulp dest scripts overwrites the original files with the output 19 For this one must first return to the required gulp uglify plugin 20 on npm package installer and at the beginning of gulpfile the module should be defined Script task gulp task scripts function return gulp src scripts js pipe uglify pipe gulp dest scripts Watch Task EditThe Watch task serves to react to changes in files In the following example the tasks with the names scripts and images are called when any of JavaScript files or images change in the specified directories 21 Rerun the task When a file changes gulp task watch function cb gulp watch scripts js scripts gulp watch images images cb Furthermore it is possible to accomplish an update of the browser content using the Watch tasks 22 For this there are numerous options and plugins See also EditGrunt software BrowserifyReferences Edit Release Date of Version 1 0 0 Retrieved 2020 12 31 Releases gulpjs gulp GitHub Retrieved 2020 12 31 LICENSE file on GitHub GitHub Retrieved 2020 12 31 License field from gulp npm Retrieved 2020 12 31 a b Jed Mao Maximilian Schmitt Tomasz Stryjewski Cary Country Holt William Lubelski 2014 Developing a Gulp Edge 1st ed Bleeding Edge Press ISBN 978 1 939902 14 6 Building With Gulp Smashing Magazine Smashingmagazine com 11 June 2014 Retrieved 2016 12 14 gulp js plugin registry Gulpjs com Retrieved 2016 12 14 gulpjs gulp GitHub Retrieved 2016 09 22 a b substack stream handbook how to write node programs with streams GitHub Retrieved 2016 12 14 gulpjs gulp GitHub Retrieved 2016 09 22 a b gulpjs gulp GitHub Retrieved 2016 09 23 Gulp for Beginners CSS Tricks 2015 09 01 Retrieved 2016 12 14 install npm Documentation docs npmjs com Retrieved 2016 09 22 a b gulpjs gulp GitHub Retrieved 2016 09 23 a b c d Maynard Travis 2015 Getting Started with Gulp Packt Publishing Ltd ISBN 9781784393472 a b An Introduction to Gulp js SitePoint 2014 02 10 Retrieved 2016 09 23 gulp API md at 4 0 gulpjs gulp GitHub GitHub 2016 05 12 Retrieved 2016 12 14 Durchstarten mit Gulp js Websites optimieren Arbeitsablaufe automatisieren Magazin phlow de 2014 05 25 Retrieved 2016 12 14 Front end Workflow mit Gulp Liechtenecker Liechtenecker at 2015 05 29 Retrieved 2016 12 14 gulp uglify Npmjs com Retrieved 2016 12 14 gulp watch Npmjs com Retrieved 2016 09 23 Browsersync Gulp js Browsersync io Retrieved 2016 12 14 Literature EditJed Mao Maximilian Schmitt Tomasz Stryjewski Cary Country Holt William Lubelski 2014 Developing a Gulp Edge 1st ed Bleeding Edge Press ISBN 978 1 939902 14 6 Den Odell 2014 Build Tools and Automation Pro JavaScript Development Coding Capabilities and Tooling Apress ISBN 978 1 4302 6268 8 Maynard Travis 2015 Getting Started with Gulp Packt Publishing Ltd ISBN 9781784393472 External links EditOfficial website nbsp gulp on GitHub Retrieved from https en wikipedia org w index php title Gulp js amp oldid 1164430631, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.