armin/scssphp-bundle

Symfony bundle to parse scss sources at runtime.

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0.5 2019-07-21 19:21 UTC

README

This bundle for Symfony Framework 4, includes the scssphp/scssphp package, which allows you to parse SCSS sources (like Bootstrap) in your application, without need of Node.js and npm!

The ScssPHP bundle can recognize changes in SCSS source files (or Symfony configuration) automatically and only re-compiles those files. So, when you change something in your SCSS sources and refresh the application you see the results, instantly. You can disable this for the production environment.

Also, it provides a helpful debugger toolbar entry and a command which allows you to compile the SCSS sources from CLI.

It is released under MIT license.

Features

  • Compile SCSS sources (like the Bootstrap framework) with pure PHP (thanks to scssphp/scssphp)
  • Simple but powerful asset configuration (e.g. set variable values)
  • Several output-formatter available (nested, compressed, crushed, etc.)
  • Inline source map support
  • Profiler Toolbar Debugging
  • Symfony Command to compile SCSS sources on CLI
  • Auto-update, when sources (or configuration) changes

Screenshots

ScssPHP in Symfony's profiler toolbar:

ScssPHP in Symfony's profiler toolbar

Hovering over ScssPHP profiler toolbar entry:

Hovering over ScssPHP profiler toolbar entry.

ScssPHP profiler panel:

ScssPHP profiler panel.

Display of SCSS compiling errors:

Display of SCSS compiling errors.

Details of recent SCSS builds:

Details of recent SCSS builds

CLI command (with compiling error)

$ php/bin console scssphp:compile

CLI command (with compiling error)

Non-interactive CLI command

$ php/bin console scssphp:compile all -n

Non-interactive CLI command

Installation

To install the scssphp-bundle you can just use composer:

$ composer require armin/scssphp-bundle

The bundle also ships a Symfony Flex Recipe.

Usage and configuration

The scssphp bundle is triggered, when you use the {{ asset("...") }} function in your Twig templates, and the requested asset is configured in scssphp.assets and scssphp.enabled is true.

Example asset call in twig:

<link href="{{ asset('styles/main.css') }}" rel="stylesheet">

Example configuration

For this example you also need to require the Bootstrap CSS framework:

$ composer require twbs/bootstrap:"^4.0"
# config/packages/scssphp.yaml
scssphp:
    assets:
        "css/styles.css":
            src: "assets/main.scss"
            sourceMap: true
            importPaths:
                - "vendor/twbs/bootstrap/scss"
            variables:
                primary: '#ff0066'

Reference

# On CLI: php bin/console config:dump scssphp

# Default configuration for extension with alias: "scssphp"
scssphp:

    # When disabled, ScssPHP will not compile SCSS sources automatically, 
    # by user's request. Compiling with CLI tool will still work.
    enabled:              true

    # Automatically re-compile SCSS sources on updates, when enabled.
    autoUpdate:           true

    # List of SCSS assets, which should be compiled, when requested. Key is the asset name/path.
    assets:
        -
            # Path to SCSS source file (entrypoint), relative to Symfony's project directory.
            src:                  ~ # Required

            # Prepends this outputFolder to asset's destination path.
            outputFolder:         public

            # Array of import paths, relative to Symfony's project directory.
            importPaths:          []

            # Array of scss variables, which should be used during compilation. Use key => value here.
            variables:            []

            # The formatter which should be used when creating CSS output.
            formatter:            ScssPhp\ScssPhp\Formatter\Crunched 
            # One of: 
            # - "ScssPhp\\ScssPhp\\Formatter\\Expanded"
            # - "ScssPhp\\ScssPhp\\Formatter\\Nested"
            # - "ScssPhp\\ScssPhp\\Formatter\\Compressed"
            # - "ScssPhp\\ScssPhp\\Formatter\\Compact"
            # - "ScssPhp\\ScssPhp\\Formatter\\Crunched"

            # When enabled, the CSS file contains inline sourceMap comments.
            sourceMap:            false

            # When enabled, the timestamp of the asset, will be appended as query string.
            appendTimestamp:      true

Support

If you like this Symfony bundle, you can donate some funds to support further development. Thank you!

For help please visit the issue section on Github.