How can we use the client-side functionality of RaptorJS in PHP?

108 views
Skip to first unread message

Patrick Steele-Idem

unread,
Aug 2, 2013, 1:39:00 PM8/2/13
to rapt...@googlegroups.com
This question was originally posted in the Disqus comments, but I'll answer here since this forum is more easily searchable. Original question:
How can we use the client-side functionality of RaptorJS in PHP? Thanks.

Answer:
RaptorJS includes a collection of core AMD modules and you will likely be creating your own set of modules. Each module should have a package.json file that describes what its dependencies are (i.e., the list of JS, CSS or other modules that the module depends on). For a given set of modules, the RaptorJS Optimizer will read all of the related package.json files to generate an optimized JavaScript and/or CSS resource bundle that includes of the required code for the modules to function. As a web developer, you just need to include the generated JS and/or CSS files in your page.

The RaptorJS Optimizer can either be executed from the command line or it can be used programmatically inside a Node.js application. To use the RaptorJS Optimizer from the command line you will need to do the following:
  1. Install the latest version of Node.js: http://nodejs.org/
  2. Run:
    npm install raptor --global

    Or, on Mac/Linux:
    sudo npm install raptor --global
  3. The above command will install a "raptor-optimizer" executable into your PATH that you can then easily execute anywhere on your system. The usage is described on the following page in the RaptorJS docs:
    http://raptorjs.org/optimizer/get-started-cli/
Basic usage example:
raptor-optimizer raptor raptor/widgets my-module another module --name my-page --minify

If both JS and CSS is included in the set of dependencies then two bundles will be generated:
  1. my-page.js
  2. my-page.css
If you want to generate optimized resource bundles for multiple modules and that include checksums and a JSON file that includes the HTML markup to include those optimized bundles you can run the following command:
raptor-optimizer raptor raptor/widgets my-module another module --name my-page --minify --html --checksum

Or, you can use a single package.json file as input:
raptor-optimizer ./package.json --name my-page --minify --html --checksum

Hopefully that clarifies.

--Patrick

Reply all
Reply to author
Forward
0 new messages