axllent/silverstripe-minifier

CSS & JavaScript minifier for Silverstripe

Installs: 20 355

Dependents: 2

Suggesters: 0

Security: 0

Stars: 8

Watchers: 4

Forks: 3

Open Issues: 0

Type:silverstripe-vendormodule

2.0.0 2024-01-29 18:17 UTC

This package is auto-updated.

Last update: 2024-10-18 21:14:04 UTC


README

Automatically minify combined CSS & JavaScript files in Silverstripe 5 when running Requirements::process_combined_files(). Internally it uses matthiasmullie/minify to remove whitespace, strips comments and combines files.

This is useful if you do not require any JavaScript bundling or transpiling (eg: webpak, esbuild etc) but you still wish to minify the combined CSS and JavaScript files.

Requirements

  • Silverstripe ^5

Installation

composer require axllent/silverstripe-minifier

This module is plug-and-play, no configuration required after installing and running a ?flush.

Usage example

<?php

use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\View\Requirements;

class PageController extends ContentController
{
    /**
     * Init function
     *
     * @return void
     */
    protected function init()
    {
        parent::init();

        $css[] = 'themes/site/css/file1.css';
        $css[] = 'themes/site/css/file2.css';
        $css[] = 'themes/site/css/file3.css';
        Requirements::combine_files('combined.css', $css);
        Requirements::process_combined_files();

        $js[] = 'themes/site/js/file1.js';
        $js[] = 'themes/site/js/file2.js';
        $js[] = 'themes/site/js/file3.js';
        Requirements::combine_files('combined.js', $js);
        Requirements::process_combined_files();
    }
}