2017 © Pedro Peláez
 

hostnet-lib asset-lib

Tool for finding all dependencies given a set of input files.

image

hostnet/asset-lib

Tool for finding all dependencies given a set of input files.

  • Monday, July 30, 2018
  • by yannickl88
  • Repository
  • 4 Watchers
  • 0 Stars
  • 5,925 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 4 Open issues
  • 32 Versions
  • 51 % Grown

The README.md

Note: Due to the fast changing ecosystem and better javascript support in popular frameworks, this lib has been deprecated with no direct alternative., (*1)


, (*2)

Build Status, (*3)

Assets can be manged in different ways. This project aims to provide a way to build assets incrementally without the need of specialized tools such as watchers and therefore requires no change in your development workflow., (*4)

This library allows you to create a generic asset pipeline and also provides some built-in processors to get you started quickly., (*5)

Core features are: - Incremental changes without a watcher - Plugin architecture to add your own processing - Leverages the parallelization of NodeJS for fast processing - Works on both Linux and Windows, (*6)

Why use this over webpack?

This project allows for incremental changes without the need for a watcher. Moreover, because the code to check for changes is build in PHP, it has very little overhead when integrated into a PHP development workflow., (*7)

Why not use a watcher?

Watchers are great if you develop a single project. However, the resource usage can grow when having multiple project. Building assets (in development) when reloading a page only taxes your system when actually needed., (*8)

Installation

Instalation can be done using composer:, (*9)

composer require hostnet/asset-lib

Usage

In the following example we have a setup for building multiple JS files into one large JS file and we added support for less., (*10)

For our input we have: - ./assets/app.js - ./assets/module-a.js (imported by app.js) - ./assets/module-b.js (imported by app.js) - ./assets/styles.less, (*11)

This will output: - ./web/dist/app.js - ./web/dist/styles.css, (*12)

Using the following snippet to build the assets. It is recommended to add it to something like a front-controller to build every time a request comes in so once a response comes back, all your assets are ready., (*13)

$config = new \Hostnet\Component\Resolver\Config\SimpleConfig(
    true, // is dev
    __DIR__,
    [],
    ['app.js'],
    ['styles.less'],
    'web',
    'dist',
    'assets',
    __DIR__ . '/var',
    [
        new \Hostnet\Component\Resolver\Plugin\CorePlugin(),
        new \Hostnet\Component\Resolver\Plugin\LessPlugin(),
    ],
    new \Hostnet\Component\Resolver\Import\Nodejs\Executable('/usr/bin/node', __DIR__ . '/node_modules/')
);

$packer = new \Hostnet\Component\Resolver\Packer();
$packer->pack($config);

The project root should be the folder which contains your package.json and composer.json., (*14)

For the Symfony framework integration already exists in the form of the asset-bundle., (*15)

Including the made javascript

To use the entry-points, you need to do: 1. Include the outputted require.js file in the head of your HTML files 2. Include the outputted assets (in the example dist/app.js) 3. require the entry point module., (*16)

As an example:, (*17)

<html>
<head>
     <script type="text/javascript" src="/dist/require.js"></script>
</head>
<body>
    <script type="text/javascript" src="/dist/app.js"></script>
    <script>
        require('app.js');
    </script>
</body>
</html>

Built-in processors

The library comes with some built-in processors to get you started more quickly with common tasks. These are: * \Hostnet\Component\Resolver\Plugin\CorePlugin * Allows for combining Javascript files into modules * CSS assets * \Hostnet\Component\Resolver\Plugin\BrotliPlugin * Used to also compress output files with Brotli * requires additionally brotli/compress * \Hostnet\Component\Resolver\Plugin\CssFontRewritePlugin * Re-writes fonts in CSS files and adds them to the outputted list * \Hostnet\Component\Resolver\Plugin\GzipPlugin * Used to also compress output files with Gzip * \Hostnet\Component\Resolver\Plugin\LessPlugin * Allows for less compilation * requires additionally less * \Hostnet\Component\Resolver\Plugin\MinifyPlugin * Compresses output files using minification * requires additionally uglifyjs and cleancss * \Hostnet\Component\Resolver\Plugin\TsPlugin * Allows for typescript compilation * requies additionally typescript, (*18)

Creating your own plugin

If the built-in support is not sufficent enough, you can add your own by creating a plugin. You do this by implementing the Hostnet\Component\Resolver\Plugin\PluginInterface interface and adding your class to the configuration., (*19)

<?php
use Hostnet\Component\Resolver\Plugin\PluginApi;
use Hostnet\Component\Resolver\Plugin\PluginInterface;

class MyPlugin implements PluginInterface
{
    public function activate(PluginApi $plugin_api): void
    {
        // $plugin_api->addBuildStep(new MyBuildStep());
        // $plugin_api->addCollector(new MyCollector());
        // $plugin_api->addWriter(new MyWriter());
    }
}
BuildStep classes

Each build step represent a processing action for either a file or a module. This can be converting typescript to javascript, uglification or anything other that needs to be done to a file before it can be outputted., (*20)

See Hostnet\Component\Resolver\Builder\AbstractBuildStep for more information., (*21)

ImportCollector classes

Each import collector is responsible for finding additional files to include in the build steps so your assets will work correctly. All files returned by the collector will be tracked for changes. For instance, imported javascript files or fonts in stylesheets etc., (*22)

See Hostnet\Component\Resolver\Import\ImportCollectorInterface for more information., (*23)

Writer classes

Each writer will write the content of a generated asset to disk. Having multiple writers means you can write the file in different formats. For instance, you might want to output a gziped version of a file if your web-server does not gzip this natively., (*24)

See Hostnet\Component\Resolver\Builder\AbstractWriter for more information., (*25)

License

The hostnet/asset-lib is licensed under the MIT License, meaning you can reuse the code within proprietary software provided that all copies of the licensed software include a copy of the MIT License terms and the copyright notice., (*26)

Get in touch

  • If you have a question, issue or feature request, you can use the github issue tracker.
  • Or via our email: opensource@hostnet.nl.

The Versions

30/07 2018

dev-master

9999999-dev

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

30/07 2018

0.1.10

0.1.10.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

25/07 2018

0.1.9

0.1.9.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/07 2018

0.1.8

0.1.8.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

23/07 2018

0.1.7

0.1.7.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/07 2018

0.1.6

0.1.6.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

10/07 2018

0.1.5

0.1.5.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/07 2018

0.1.4

0.1.4.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/07 2018

0.1.3

0.1.3.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/07 2018

0.1.2

0.1.2.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/07 2018

0.1.1

0.1.1.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/06 2018

0.1.0

0.1.0.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/06 2018

0.0.20

0.0.20.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

04/04 2018

0.0.19

0.0.19.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/03 2018

0.0.18

0.0.18.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

30/01 2018

0.0.17

0.0.17.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

30/01 2018

0.0.16

0.0.16.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/01 2018

0.0.15

0.0.15.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/01 2018

0.0.14

0.0.14.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

25/01 2018

0.0.13

0.0.13.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

25/01 2018

0.0.12

0.0.12.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

25/01 2018

0.0.11

0.0.11.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/01 2018

0.0.10

0.0.10.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/01 2018

0.0.9

0.0.9.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/01 2018

0.0.8

0.0.8.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/01 2018

0.0.7

0.0.7.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/01 2018

0.0.6

0.0.6.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

21/12 2017

0.0.5

0.0.5.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/12 2017

0.0.4

0.0.4.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

14/12 2017

0.0.3

0.0.3.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

14/12 2017

0.0.2

0.0.2.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires

30/11 2017

0.0.1

0.0.1.0

Tool for finding all dependencies given a set of input files.

  Sources   Download

MIT

The Requires

 

The Development Requires