{"action":"created","issue":{"url":"https://api.github.com/repos/gulpjs/gulp/issues/1305","labels_url":"https://api.github.com/repos/gulpjs/gulp/issues/1305/labels{/name}","comments_url":"https://api.github.com/repos/gulpjs/gulp/issues/1305/comments","events_url":"https://api.github.com/repos/gulpjs/gulp/issues/1305/events","html_url":"https://github.com/gulpjs/gulp/issues/1305","id":109710982,"number":1305,"title":"Exports as tasks","user":{"login":"thejameskyle","id":952783,"avatar_url":"https://avatars.githubusercontent.com/u/952783?v=3","gravatar_id":"","url":"https://api.github.com/users/thejameskyle","html_url":"https://github.com/thejameskyle","followers_url":"https://api.github.com/users/thejameskyle/followers","following_url":"https://api.github.com/users/thejameskyle/following{/other_user}","gists_url":"https://api.github.com/users/thejameskyle/gists{/gist_id}","starred_url":"https://api.github.com/users/thejameskyle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejameskyle/subscriptions","organizations_url":"https://api.github.com/users/thejameskyle/orgs","repos_url":"https://api.github.com/users/thejameskyle/repos","events_url":"https://api.github.com/users/thejameskyle/events{/privacy}","received_events_url":"https://api.github.com/users/thejameskyle/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/gulpjs/gulp/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/gulpjs/gulp/labels/gulp4","name":"gulp4","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-04T23:03:23Z","updated_at":"2015-10-19T22:18:57Z","closed_at":null,"body":"One of the things I've started doing in all my gulpfiles is to write tasks as plain functions and then write `gulp.task` at the end of the file. This makes abstraction a bit easier and avoids using IDs for composition instead of just functions, making writing large complex gulpfiles much much easier to follow.\r\n\r\n```js\r\nfunction test() { ... }\r\ngulp.task('test', test);\r\n```\r\n\r\nThis gets a lot easier with gulp 4 using `series` and `parallel`.\r\n\r\n```js\r\nfunction test() { ... }\r\nfunction buildFiles() { ... }\r\nvar build = gulp.series(test, buildFiles);\r\ngulp.task('test', test);\r\ngulp.task('build', build);\r\n```\r\n\r\nBut at this point writing out `gulp.task` seems a bit unnecessary since the `id` isn't being used in the code and is only there to export a set of tasks.\r\n\r\nI'd prefer just to write:\r\n\r\n```js\r\nexports.test = test;\r\nexports.build = build;\r\n```\r\n\r\nNow this gets even more interesting with ES2015 because you can write:\r\n\r\n```js\r\nexport function test() { ... }\r\nexport function build() { ... }\r\n```\r\n\r\nOne of the cool benefits here is that you can use static analysis to determine which tasks the `gulpfile` defines and use it for stuff like CLI autocompletion:\r\n\r\n```sh\r\n$ gulp [tab]\r\n  - test\r\n  - build\r\n  - dev\r\n```\r\n\r\nBut the bigger benefit here is that it encourages people to write gulp tasks as plain functions that return streams, making them far more generic and simplifying the gulp API greatly. \r\n\r\nThis is what gulpfiles could look like in the future: https://gist.github.com/thejameskyle/2778e4df363612635989\r\n\r\nHow would you all feel about allowing tasks to be defined as exports?"},"comment":{"url":"https://api.github.com/repos/gulpjs/gulp/issues/comments/149363854","html_url":"https://github.com/gulpjs/gulp/issues/1305#issuecomment-149363854","issue_url":"https://api.github.com/repos/gulpjs/gulp/issues/1305","id":149363854,"user":{"login":"thejameskyle","id":952783,"avatar_url":"https://avatars.githubusercontent.com/u/952783?v=3","gravatar_id":"","url":"https://api.github.com/users/thejameskyle","html_url":"https://github.com/thejameskyle","followers_url":"https://api.github.com/users/thejameskyle/followers","following_url":"https://api.github.com/users/thejameskyle/following{/other_user}","gists_url":"https://api.github.com/users/thejameskyle/gists{/gist_id}","starred_url":"https://api.github.com/users/thejameskyle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejameskyle/subscriptions","organizations_url":"https://api.github.com/users/thejameskyle/orgs","repos_url":"https://api.github.com/users/thejameskyle/repos","events_url":"https://api.github.com/users/thejameskyle/events{/privacy}","received_events_url":"https://api.github.com/users/thejameskyle/received_events","type":"User","site_admin":false},"created_at":"2015-10-19T22:18:57Z","updated_at":"2015-10-19T22:18:57Z","body":"> it is too much an undertaking to rewrite everything\r\n\r\nToo bad there isn't an **undertaker** to do this. *shitty rimshot*\r\n\r\nThat's fine then, I was just wondering."}}