-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy path5a61639a.2155963e.js
1 lines (1 loc) · 8.43 KB
/
5a61639a.2155963e.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{108:function(e,t,n){"use strict";n.d(t,"a",(function(){return u})),n.d(t,"b",(function(){return m}));var r=n(0),a=n.n(r);function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function c(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=a.a.createContext({}),b=function(e){var t=a.a.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},u=function(e){var t=b(e.components);return a.a.createElement(l.Provider,{value:t},e.children)},p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},d=a.a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,s=e.originalType,i=e.parentName,l=c(e,["components","mdxType","originalType","parentName"]),u=b(n),d=r,m=u["".concat(i,".").concat(d)]||u[d]||p[d]||s;return n?a.a.createElement(m,o(o({ref:t},l),{},{components:n})):a.a.createElement(m,o({ref:t},l))}));function m(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var s=n.length,i=new Array(s);i[0]=d;var o={};for(var c in t)hasOwnProperty.call(t,c)&&(o[c]=t[c]);o.originalType=e,o.mdxType="string"==typeof e?e:r,i[1]=o;for(var l=2;l<s;l++)i[l]=n[l];return a.a.createElement.apply(null,i)}return a.a.createElement.apply(null,n)}d.displayName="MDXCreateElement"},79:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return o})),n.d(t,"toc",(function(){return c})),n.d(t,"default",(function(){return b}));var r=n(3),a=n(8),s=(n(0),n(108)),i={id:"series",title:"series()",hide_title:!0,sidebar_label:"series()"},o={unversionedId:"api/series",id:"api/series",isDocsHomePage:!1,title:"series()",description:"series()",source:"@site/docs/api/series.md",slug:"/api/series",permalink:"/docs/en/api/series",version:"current",sidebar_label:"series()",sidebar:"docs",previous:{title:"lastRun()",permalink:"/docs/en/api/lastrun"},next:{title:"parallel()",permalink:"/docs/en/api/parallel"}},c=[{value:"Usage",id:"usage",children:[]},{value:"Signature",id:"signature",children:[{value:"Parameters",id:"parameters",children:[]},{value:"Returns",id:"returns",children:[]},{value:"Errors",id:"errors",children:[]}]},{value:"Forward references",id:"forward-references",children:[]},{value:"Avoid duplicating tasks",id:"avoid-duplicating-tasks",children:[]}],l={toc:c};function b(e){var t=e.components,n=Object(a.a)(e,["components"]);return Object(s.b)("wrapper",Object(r.a)({},l,n,{components:t,mdxType:"MDXLayout"}),Object(s.b)("h1",{id:"series"},"series()"),Object(s.b)("p",null,"Combines task functions and/or composed operations into larger operations that will be executed one after another, in sequential order. There are no imposed limits on the nesting depth of composed operations using ",Object(s.b)("inlineCode",{parentName:"p"},"series()")," and ",Object(s.b)("inlineCode",{parentName:"p"},"parallel()"),"."),Object(s.b)("h2",{id:"usage"},"Usage"),Object(s.b)("pre",null,Object(s.b)("code",Object(r.a)({parentName:"pre"},{className:"language-js"}),"const { series } = require('gulp');\n\nfunction javascript(cb) {\n // body omitted\n cb();\n}\n\nfunction css(cb) {\n // body omitted\n cb();\n}\n\nexports.build = series(javascript, css);\n")),Object(s.b)("h2",{id:"signature"},"Signature"),Object(s.b)("pre",null,Object(s.b)("code",Object(r.a)({parentName:"pre"},{className:"language-js"}),"series(...tasks)\n")),Object(s.b)("h3",{id:"parameters"},"Parameters"),Object(s.b)("table",null,Object(s.b)("thead",{parentName:"table"},Object(s.b)("tr",{parentName:"thead"},Object(s.b)("th",Object(r.a)({parentName:"tr"},{align:"center"}),"parameter"),Object(s.b)("th",Object(r.a)({parentName:"tr"},{align:"center"}),"type"),Object(s.b)("th",Object(r.a)({parentName:"tr"},{align:null}),"note"))),Object(s.b)("tbody",{parentName:"table"},Object(s.b)("tr",{parentName:"tbody"},Object(s.b)("td",Object(r.a)({parentName:"tr"},{align:"center"}),"tasks",Object(s.b)("br",null),Object(s.b)("strong",{parentName:"td"},"(required)")),Object(s.b)("td",Object(r.a)({parentName:"tr"},{align:"center"}),"function",Object(s.b)("br",null),"string"),Object(s.b)("td",Object(r.a)({parentName:"tr"},{align:null}),"Any number of task functions can be passed as individual arguments. Strings can be used if you've registered tasks previously, but this is not recommended.")))),Object(s.b)("h3",{id:"returns"},"Returns"),Object(s.b)("p",null,"A composed operation to be registered as a task or nested within other ",Object(s.b)("inlineCode",{parentName:"p"},"series")," and/or ",Object(s.b)("inlineCode",{parentName:"p"},"parallel")," compositions."),Object(s.b)("p",null,"When the composed operation is executed, all tasks will be run sequentially. If an error occurs in one task, no subsequent tasks will be run."),Object(s.b)("h3",{id:"errors"},"Errors"),Object(s.b)("p",null,'When no tasks are passed, throws an error with the message, "One or more tasks should be combined using series or parallel".'),Object(s.b)("p",null,'When invalid tasks or unregistered tasks are passed, throws an error with the message, "Task never defined".'),Object(s.b)("h2",{id:"forward-references"},"Forward references"),Object(s.b)("p",null,"A forward reference is when you compose tasks, using string references, that haven't been registered yet. This was a common practice in older versions, but this feature was removed to achieve faster task runtime and promote the use of named functions."),Object(s.b)("p",null,'In newer versions, you\'ll get an error, with the message "Task never defined", if you try to use forward references. You may experience this when trying to use ',Object(s.b)("inlineCode",{parentName:"p"},"exports")," for your task registration ",Object(s.b)("em",{parentName:"p"},"and")," composing tasks by string. In this situation, use named functions instead of string references."),Object(s.b)("p",null,"During migration, you may need to use the ",Object(s.b)("a",Object(r.a)({parentName:"p"},{href:"https://github.com/gulpjs/undertaker-forward-reference"}),"forward reference registry"),". This will add an extra closure to every task reference and dramatically slow down your build. ",Object(s.b)("strong",{parentName:"p"},"Don't rely on this fix for very long"),"."),Object(s.b)("h2",{id:"avoid-duplicating-tasks"},"Avoid duplicating tasks"),Object(s.b)("p",null,"When a composed operation is run, each task will be executed every time it was supplied."),Object(s.b)("p",null,"A ",Object(s.b)("inlineCode",{parentName:"p"},"clean")," task referenced in two different compositions would be run twice and lead to undesired results. Instead, refactor the ",Object(s.b)("inlineCode",{parentName:"p"},"clean")," task to be specified in the final composition."),Object(s.b)("p",null,"If you have code like this:"),Object(s.b)("pre",null,Object(s.b)("code",Object(r.a)({parentName:"pre"},{className:"language-js"}),"// This is INCORRECT\nconst { series, parallel } = require('gulp');\n\nconst clean = function(cb) {\n // body omitted\n cb();\n};\n\nconst css = series(clean, function(cb) {\n // body omitted\n cb();\n});\n\nconst javascript = series(clean, function(cb) {\n // body omitted\n cb();\n});\n\nexports.build = parallel(css, javascript);\n")),Object(s.b)("p",null,"Migrate to this:"),Object(s.b)("pre",null,Object(s.b)("code",Object(r.a)({parentName:"pre"},{className:"language-js"}),"const { series, parallel } = require('gulp');\n\nfunction clean(cb) {\n // body omitted\n cb();\n}\n\nfunction css(cb) {\n // body omitted\n cb();\n}\n\nfunction javascript(cb) {\n // body omitted\n cb();\n}\n\nexports.build = series(clean, parallel(css, javascript));\n")))}b.isMDXComponent=!0}}]);