You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: elixir.md
+41-11
Original file line number
Diff line number
Diff line change
@@ -293,36 +293,66 @@ Now that you've told Elixir which tasks to execute, you only need to trigger Gul
293
293
> **Note:** All tasks will assume a development environment, and will exclude minification. For production, use `gulp --production`.
294
294
295
295
<aname="extensions"></a>
296
-
## Extensions
296
+
## Custom Tasks and Extensions
297
297
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:
300
330
301
331
```javascript
302
332
var gulp =require("gulp");
303
333
var shell =require("gulp-shell");
304
334
var elixir =require("laravel-elixir");
305
335
306
-
elixir.extend("message", function(message) {
336
+
elixir.extend("speak", function(message) {
307
337
308
-
gulp.task("say", function() {
338
+
gulp.task("speak", function() {
309
339
gulp.src("").pipe(shell("say "+ message));
310
340
});
311
341
312
-
returnthis.queueTask("say");
342
+
returnthis.queueTask("speak");
313
343
314
344
});
315
345
```
316
346
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.
318
348
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.
320
350
321
351
```javascript
322
-
this.registerWatcher("message", "**/*.php");
352
+
this.registerWatcher("speak", "app/**/*.php");
323
353
```
324
354
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.
326
356
327
357
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:
328
358
@@ -334,7 +364,7 @@ You're done! Now, you can mix it in.
0 commit comments