03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Deployment 97<br />

43 {<br />

44 $options["type"] = "js";<br />

45 $this->call("asset:minify", $options);<br />

46 }<br />

47 else<br />

48 {<br />

49 $this->call("asset:combine", $options);<br />

50 }<br />

51 }<br />

52 }<br />

53 }<br />

54 }<br />

.<br />

This file should be saved as app/commands/BuildCommand.php.<br />

The BuildCommand class fetches the asset lists, from the configuration files, and iterates over them;<br />

combining/minifying as needed. It does this by checking file extensions. If the file ends in .min.js<br />

then the minify command is run in js mode. Files ending in .min.css are minified in css mode, and<br />

so forth.<br />

The app/config/*/asset.php files are environment-based. This means running the build command<br />

will build the assets for the current environment. Often this will not be the environment you want<br />

to build assets for. I often build assets on my local machine, yet I want assets built for production.<br />

When that is the case; I provide the –env=production flag to the build command.<br />

Watching Assets<br />

So we have the tools to combine, minify and even build our asset files. It’s a pain to have to remember<br />

to do those things all the time (especially when files are being updated at a steady pace), so we’re<br />

going to take it a step further by adding a file watcher.<br />

Remember the Resource Watcher library we added to composer.json? Well we need to add it to the<br />

list of service providers:<br />

1 "providers" => [<br />

2 // other service providers here<br />

3 "JasonLewis\ResourceWatcher\Integration\LaravelServiceProvider"<br />

4 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!