Skip to content

Commit 581956e

Browse files
committed
Add Elixir note about mixing custom Gulp tasks
1 parent 3e27a81 commit 581956e

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

elixir.md

+41-11
Original file line numberDiff line numberDiff line change
@@ -293,36 +293,66 @@ Now that you've told Elixir which tasks to execute, you only need to trigger Gul
293293
> **Note:** All tasks will assume a development environment, and will exclude minification. For production, use `gulp --production`.
294294
295295
<a name="extensions"></a>
296-
## Extensions
296+
## Custom Tasks and Extensions
297297

298-
You can even create your own Gulp tasks, and hook them into Elixir. Imagine that you want to add a fun task that
299-
uses the Terminal to verbally notify you with some message. Here's what that might look like:
298+
Sometimes, you'll want to hook your own Gulp tasks into Elixir. Perhaps you have a special bit of functionality that you'd like Elixir to mix and watch for you. No problem!
299+
300+
As an example, imagine that you have a general task that simply speaks a bit of text when called.
301+
302+
```javascript
303+
gulp.task("speak", function() {
304+
var message = "Tea...Earl Grey...Hot";
305+
306+
gulp.src("").pipe(shell("say " + message));
307+
});
308+
```
309+
310+
Easy enough. From the command line, you may, of course, call `gulp speak` to trigger the task. To add it to Elixir, however, use the `mix.task()` method:
311+
312+
```javascript
313+
elixir(function(mix) {
314+
mix.task('speak');
315+
});
316+
```
317+
318+
That's it! Now, each time you run Gulp, your custom "speak" task will be executed alongside any other Elixir tasks that you've mixed in. To additionally register a watcher, so that your custom tasks will be re-triggered each time one or more files are modified, you may pass a regular expression as the second argument.
319+
320+
```javascript
321+
elixir(function(mix) {
322+
mix.task('speak', 'app/**/*.php');
323+
});
324+
```
325+
326+
By adding this second argument, we've instructed Elixir to re-trigger the "speak" task each time a PHP file in the "app/" directory is saved.
327+
328+
329+
For even more flexibility, you can create full Elixir extensions. Using the previous "speak" example, you may write an extension, like so:
300330

301331
```javascript
302332
var gulp = require("gulp");
303333
var shell = require("gulp-shell");
304334
var elixir = require("laravel-elixir");
305335

306-
elixir.extend("message", function(message) {
336+
elixir.extend("speak", function(message) {
307337

308-
gulp.task("say", function() {
338+
gulp.task("speak", function() {
309339
gulp.src("").pipe(shell("say " + message));
310340
});
311341

312-
return this.queueTask("say");
342+
return this.queueTask("speak");
313343

314344
});
315345
```
316346

317-
Notice that we `extend` Elixir's API by passing the key that we will use within our Gulpfile, as well as a callback function that will create the Gulp task.
347+
Notice that we `extend` Elixir's API by passing the name that we will reference within our Gulpfile, as well as a callback function that will create the Gulp task.
318348

319-
If you want your custom task to be monitored, then register a watcher as well.
349+
As before, if you want your custom task to be monitored, then register a watcher.
320350

321351
```javascript
322-
this.registerWatcher("message", "**/*.php");
352+
this.registerWatcher("speak", "app/**/*.php");
323353
```
324354

325-
This lines designates that when any file that matches the regex, `**/*.php` is modified, we want to trigger the `message` task.
355+
This lines designates that when any file that matches the regular expression, `app/**/*.php`, is modified, we want to trigger the `speak` task.
326356

327357
That's it! You may either place this at the top of your Gulpfile, or instead extract it to a custom tasks file. If you choose the latter approach, simply require it into your Gulpfile, like so:
328358

@@ -334,7 +364,7 @@ You're done! Now, you can mix it in.
334364

335365
```javascript
336366
elixir(function(mix) {
337-
mix.message("Tea, Earl Grey, Hot");
367+
mix.speak("Tea, Earl Grey, Hot");
338368
});
339369
```
340370

0 commit comments

Comments
 (0)