By Ryan Florence, published 2010-10-14
Part of the issue MooTools 1.3.
Get it from github.
During Development – Packager PHP
<script src="http://localhost/build.php?scripts=Core/Fx.Tween"></script> <script src="page.js"></script>
This is part of my github repository mootools-template. The file
build.php lives next to a directory named
build.php looks like:
Pretty straightforward PHP. It first builds up an array of sub-directories in
Packager instance, and passes it the array of directories. Next it decides if the url indicates to write the file, or just echo it out by checking for a
path key. Finally, it calls either
write_from_components and writes a file or
Here’s a less dynamic example:
Building files from the command line is straightforward.
# build the file (with dependencies, this command pulls in 35 files) ./packager build Core/DOMReady More/Fx.Move > ~/path/to/site/build.js
First you register your package, next you build. Easy enough
Making your stuff work with Packager
Packager is not very picky. It only requires two things: a
package.yml manifest in the root directory, and a YAML header in your script file. Here is a bare bones example, containing only the information Packager needs.
my-plugin/ package.yml Source/ MyPlugin.js MyPlugin.Extended.js
sources: - Source/MyPlugin.js - Source/MyPlugin.Extended.js
/* --- requires: - Core/Fx - ExternalPackage/Script - /MyPlugin.Extended
// ... some code
All you need to do:
package.ymlin the root directory
- Give the package a name
- Point to the sources
- Declare what a script requires, note that way local and scripts are required vs. external (beginning
- Declare what a script provides, doesn’t have to match the file name or anything, it’s just a name.
On a recent project I was using jQuery. I went ahead and made every jQuery UI script work with Packager, and it was fabulous. Yes, that’s right, it has nothing to do with MooTools, Packager works with any files that follow these simple conventions.
Go back to the previous article in this issue: MooTools Element 1.3.