nanjingboy/assetloader

A simple tool to load javascript & css files

v0.1.7 2014-11-14 08:20 UTC

This package is not auto-updated.

Last update: 2024-12-17 03:46:07 UTC


README

AssetLoader:

AssetLoader is a simple library to load javascript & css files.

Getting Started:

  • Create composer.json file in root directory of your application:
 {
    "require": {
        "php": ">=5.4.0",
        "nanjingboy/assetloader": "*"
    }
}
  • Install it via composer

  • Create directory in root directory of your application:

 $ mkdir tmp/assetLoader -p
 $ chmod -R a+w tmp
  • Init the config in your bootstrap.php:
<?php
require __DIR__ . '/vendor/autoload.php';
AssetLoader::init($serverRootPath, $jsDirectoryPath, $cssDirectoryPath);

Usage:

We can use the require or require_dir directive to load the dependencies, there are the formats for this directive below:

  • CoffeeScript:
# require dependency
# require_dir dependency_dir
  • JavaScript, Scss, Less:
// require dependency
// require_dir dependency_dir
  • JavaScript, Css, Scss, Less(single line):
/* require dependency */
/* require_dir dependency_dir */
  • JavaScript, Css, Scss, Less(multi line):
/**
 * require one_dependency
 * require two_dependency
 * require_dir dependency_dir
 */

Notes:

  • The require comments must on the top in a asset file.
  • The dependency's path is relative with the root directory path of your javascripts or stylesheets.
  • The require_dir directive auto load all files in this directory without recursive.
  • It's just used to parse the load paths for asset's dependencies, it can't compile any files(e.g. a coffeeScript file).

Example:

Get a example from test

License:

MIT