Skip to content

Commit cf9c704

Browse files
committed
Add section about deployment to README
1 parent 2385a49 commit cf9c704

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,51 @@ The server also applies some conditional caching via `Last-Modified` and
341341
not be instantly visible, try to make a hard refresh in your browser or
342342
clear your browser's cache.
343343

344+
### Preparing Assets for Production Deployment
345+
346+
It's a good idea to compile assets in a way that they don't need the
347+
runtime support of Pipe. The `Pipe\Manifest` class is responsible for
348+
just that.
349+
350+
The Manifest is used to compile assets and writes a JSON encoded file
351+
which maps the logical paths (which the app knows anyway) to the paths
352+
including the digest (which the app can't know in advance).
353+
354+
To add a file to the manifest, call the manifest's `compile` method:
355+
356+
<?php
357+
358+
$env = new \Pipe\Environment;
359+
$env->appendPath('assets/javascripts');
360+
361+
$manifest = new \Pipe\Manifest($env, 'build/assets/manifest.json');
362+
$manifest->compile('index.js');
363+
364+
This creates the `index-<SHA1 digest>.js` file, and a `manifest.json`
365+
both in the `build/assets` directory.
366+
367+
This file looks a bit like this:
368+
369+
{
370+
"assets": {
371+
"index.js": "index-0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33.js"
372+
}
373+
}
374+
375+
An app running in a production environment could use the manifest like
376+
this:
377+
378+
<?php
379+
380+
# Better cache this, but omitted for brevity
381+
$manifest = json_decode(file_get_contents('/path/to/manifest.json'), true);
382+
383+
# Path where the contents of "build/assets" are deployed.
384+
# Could be a path to a CDN.
385+
$prefix = "/assets";
386+
387+
printf('<script type="text/javascript" src="%s/%s"></script>', $prefix, $manifest['index.js']);
388+
344389
## License
345390

346391
The MIT License

0 commit comments

Comments
 (0)