Assets loading with themes and skins supported. assume that different apps (or plugins) are independent with each others but share the same basic modules and public resources
A) asset cases: there are stylesheet files in public css
share by all apps
and app specific stylesheet locate in its directory. e.g.
- public/css/style.css
- public/min/css/style.min.css
- app/account/skin/default/css/account.css
- public/min/css/account.min.css
B) loading source and target
- load the min file
- a) load from public: /css/style.css ===> public/min/css/style.min.css
minify
public/css/style.css
to public/min/css/style.min.css
- b) load from app dir: css/account.css ===> public/min/css/account.min.css
minify
account/default/css/account.css
to public/min/css/account.min.css
- load the raw file
- a) load from public: /css/style.css ===> public/css/style.css
- b) load from app dir: default/css/account.css ===> public/default/css/account.css
- i) if
public/default/css/account.css
not exists,
copy account/default/css/account.css
to public/default/css/
- ii) else update
account/default/css/account.css
to public/default/css/
C) implement
- if
uri
is start with /
, it'll try to load asset from document root
$mySkin = 'Default';
// Register specific services for the module
public function registerServices(Di $di)
{
$di->assets->setOptions([
'source' => __DIR__ . '/Skin/' . $mySkin . '/',
'target' => 'min/',
'minify' => 3
]);
}
// css used by specific module
// load from module dir/Skin/Default/css/account.css
$this->assets->addCss(['css/account.css']);
// css shared by all modules
// load from document_root/Skin/Default/css/style.css
$this->assets->addCss(['/Skin/' . $mySkin . '/css/style.css']);
- always store the min files in the document_root/target dir
ONE MORE THING
type
parameter change from text/css
or text/javascript
to css
or js
$assets->addCss(['css/style.css', 'type' => 'css'])
->addCss(['js/script.js', 'type' => 'js'])
but not
$assets->addCss(['css/style.css', 'type' => 'text/css'])
->addCss(['js/script.js', 'type' => 'text/javascript'])