inspirecz / webloader
Tool for loading or deploying CSS and JS files into web pages
6.0.3
2023-05-10 13:18 UTC
Requires
- php: ^8.0
- ext-json: *
- latte/latte: ^3.0
- nette/application: ^3.1
- nette/di: ^3.0
- nette/finder: ^2.5 || ^3.0
- nette/schema: ^1.2
- nette/utils: ^3.2 || ^4.0
- tracy/tracy: ^2.8
Requires (Dev)
- mockery/mockery: 1.*
- nette/bootstrap: ^3.1
- nette/caching: ^3.1
- nette/component-model: ^3.0
- nette/http: ^3.0
- nette/neon: ^3.0
- nette/robot-loader: ^3.0 || ^4.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.0.0
- phpstan/phpstan-mockery: ^1.0.0
- phpstan/phpstan-nette: ^1.0.0
- phpunit/phpunit: 9.*
- roave/security-advisories: dev-master
- scssphp/scssphp: ^1.1.0
- symfony/console: ^4.2.9|^5.0.0|^6.0.0
- tedivm/jshrink: ^1.3
- tubalmartin/cssmin: ^4.1
- wikimedia/less.php: ^3.0.0
Suggests
- nette/safe-stream: Atomic and safe manipulation with files via native PHP functions.
- scssphp/scssphp: SCSS compiler written in PHP.
- symfony/console: For pre-generating files from CLI
- tedivm/jshrink: Javascript Minifier built in PHP
- tubalmartin/cssmin: A PHP port of the YUI CSS compressor
- wikimedia/less.php: LESS compiler written in PHP.
This package is auto-updated.
Last update: 2024-11-10 16:52:40 UTC
README
Component for CSS and JS files loading.
Author: Jan Marek Licence: MIT
Updated for Nette 3/3.1 and PHP 8.0 by Gappa.
Example
Control factory in Nette presenter:
<?php protected function createComponentCss() { $files = new WebLoader\FileCollection(WWW_DIR . '/css'); $files->addFiles(array( 'style.css', WWW_DIR . '/colorbox/colorbox.css', )); $files->addWatchFiles(Finder::findFiles('*.css', '*.less')->in(WWW_DIR . '/css')); $compiler = WebLoader\Compiler::createCssCompiler($files, WWW_DIR . '/temp'); $compiler->addFilter(new WebLoader\Filter\VariablesFilter(array('foo' => 'bar'))); $compiler->addFilter(function ($code) { return cssmin::minify($code, "remove-last-semicolon"); }); $control = new WebLoader\Nette\CssLoader($compiler, '/webtemp'); $control->setMedia('screen'); return $control; }
Template:
{control css}
Example with Nette Framework extension used
Configuration in app/config/config.neon
:
extensions: webloader: WebLoader\Nette\Extension services: wlCssFilter: WebLoader\Filter\CssUrlsFilter(%wwwDir%) lessFilter: WebLoader\Filter\LessFilter jwlCssMinFilter: Joseki\Webloader\CssMinFilter webloader: css: default: files: - style.css - {files: ["*.css", "*.less"], from: %appDir%/presenters} # Nette\Utils\Finder support filters: - @jwlCssMinFilter fileFilters: - @lessFilter - @wlCssFilter watchFiles: # only watch modify file - {files: ["*.css", "*.less"], from: css} - {files: ["*.css", "*.less"], in: css} js: default: remoteFiles: - http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js - http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js files: - %appDir%/../libs/nette/nette/client-side/netteForms.js - web.js
For older versions of Nette, you have to register the extension in app/bootstrap.php
:
$webloaderExtension = new \WebLoader\Nette\Extension(); $webloaderExtension->install($configurator);
Usage in app/presenters/BasePresenter.php
:
/** @var \WebLoader\Nette\LoaderFactory @inject */ public $webLoader; /** @return CssLoader */ protected function createComponentCss() { return $this->webLoader->createCssLoader('default'); } /** @return JavaScriptLoader */ protected function createComponentJs() { return $this->webLoader->createJavaScriptLoader('default'); }
Template:
{control css} {control js}