Giter VIP home page Giter VIP logo

webloader's Introduction

๐Ÿ“ฆ Simple, easy to use, php bundler for javascript and css.

In a nutshell

  • Configurable: in one file (example bellow or in docs)
  • Files collections and containers: makes assets organizing incredibly simple
  • Filters: callable in two different ways
  • Path placeholders: reusable paths to files, less writing
  • Allows you to load remote and local files
  • If you have some critical css, you can load it directly into the page with minimal configuration required
  • Prepared for read only deployment - webloader is able to compile all files collections at once
  • Debugger bar for Tracy

Requirements

  • PHP 8.0+
  • If you use Nette Framework - v2.4+

Installation

 composer require machy8/webloader

Docs

Quick start

Let's say we have two css files (styla-a.css and style-b.css) and we want to bundle them into one file which name will be my-bundle. This bundle will be stored in a webtemp dir (must be accessible from a browser).

The recommended way to configure Web Loader is through neon configuration files. The first step is to create a bundle.neon.

my-bundle:
    cssFiles:
        - path/to/style-a.css
        - path/to/style-b.css

Next step is to init Web Loader, set the output dir path and tell him to create bundles from bundle.neon.

$webloader = new \WebLoader\Engine('path/to/webtemp');
$webloader->createFilesCollectionsFromConfig('path/to/bundle.neon');

The last step is to call files collections render to render css files collection named my-bundle.

echo $webloader->getFilesCollectionRender()->css('my-bundle');

The PHP file after the last edit will looks like this:

$webloader = new \WebLoader\Engine('path/to/output/dir');
$webloader->createFilesCollectionsFromConfig('path/to/bundle.neon');

echo $webloader->getFilesCollectionRender()->css('my-bundle');

The output will be similiar to the following code:

<link type="text/css" rel="stylesheet" href="/path/to/webtemp/my-bundle.css?v=1512829634">

Quick start (for Nette Framework)

For the Nette Framework it is very similar. First of all, register Web Loader extension.

extensions:
    webloader: WebLoader\Bridges\Nette\WebLoaderExtension

Next step is to add Web Loader section with my-bundle collection configuration inside.

webloader:
    filesCollections:
        my-bundle:
            cssFiles:
                - path/to/style-a.css
                - path/to/style-b.css

In your presenter, inject the engine...

/**
 * @var Engine
 */
private $webLoader;


public function __construct(\WebLoader\Engine $engine)
{
    $this->webLoader = $engine;
}

and set template parameters (for example in the beforeRender method).

public function beforeRender()
{
    $this->template->webloaderFilesCollectionRender = $this->webLoader->getFilesCollectionRender();
}

The last step is to call the render in a latte template.

{$webloaderFilesCollectionRender->css('my-bundle')|noescape}

webloader's People

Contributors

machy8 avatar rikap avatar tomaspilar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

webloader's Issues

Coveralls fix

  • Fix coveralls when they start support XML file format in github action

Add filters helper for checking .min suffix

  • Files passed to the minifiers could be already minified
  • Those files usually have .min suffix
  • Helper could check if the file name already contains the suffix and eventually skip the compilation

PHP8 support

Hi Machy8 ๐Ÿ‘‹

We would like to upgrade our app to PHP8 but there are some deprecated messages because of this package.

Could you add support for PHP8, please?

New filter / module - css loading according to breakpoints

  • Add filter / module that could be able to load css according to breakpoints
  • It should separate css collection according to breakpoints
  • It should be able to load css into page according to device width and omit css that contains url()

Remove type attributes

Hi Machy8,

I think that type="text/css" and type="text/javascript" attributes are unnecessary for HTML5.

If <script type="text/javascript"> is used in the code the validator.w3.org reports
Warning: The type attribute is unnecessary for JavaScript resources.

The following outputs from Machy8/webloader would be sufficient:

  • <link rel="stylesheet" href="my-bundle.css?v=...">
  • <script src="my-bundle.js?v=..."></script>

Could you add support for HTML5 (remove type attributes), please?

Enable remote files loading

  • Update compiler.php
  • Enable remote files loading
  • Add method for setting connection timeout to prevent long loading time
  • Set default loading time for 15s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.