這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

Easy SCSS and JS

外掛說明

This plugin adds SCSS functionality, compresses JS for you and creates an easy way to enqueue scripts and styles as well as localize them.

How to use

Let’s assume this structure:
your theme
├── assets
│ ├── js
│ │ └── script.js
│ └── scss
│ └── style.scss
├── functions.php
└── …

You can now do this in your functions.php with styles:

<?php
add_action('wp_enqueue_scripts', static function(){
    /* Full version */
    \EasySCSSandJS\Styles::add('my_style_handle', __DIR__ .'/assets/scss/style.scss', [],[], true);

    /* Shortest version */
    \EasySCSSandJS\Styles::add('my_style_handle', __DIR__ .'/assets/scss/style.scss');

    /* Add dependencies (example: depends on handle 'bootstrap') */
    \EasySCSSandJS\Styles::add('my_style_handle', __DIR__ .'/assets/scss/style.scss', ['bootstrap']);

    /* Add variables */
    \EasySCSSandJS\Styles::add('my_style_handle', __DIR__ .'/assets/scss/style.scss', [], [
        'my_cool_color' => '#0000ff',
    ]);

    /* Enqueue it yourself */
    \EasySCSSandJS\Styles::add('my_style_handle', __DIR__ .'/assets/scss/style.scss', [], [], false);
    wp_enqueue_style('my_style_handle');
});

And this with scripts:

<?php
add_action('wp_enqueue_scripts', static function(){
    /* Full version */
    \EasySCSSandJS\Scripts::add('my_script_handle', __DIR__ .'/assets/js/script.js', ['jquery'], [], true, true);

    /* Shortest version (jquery is by default a dependency) */
    \EasySCSSandJS\Scripts::add('my_script_handle', __DIR__ .'/assets/js/script.js');

    /* No dependencies (also no jquery) */
    \EasySCSSandJS\Scripts::add('my_script_handle', __DIR__ .'/assets/js/script.js', []);

    /* Add dependencies (besides jquery) */
    \EasySCSSandJS\Scripts::add('my_script_handle', __DIR__ .'/assets/js/script.js', ['jquery', 'other_script']);

    /* Add variables */
    \EasySCSSandJS\Scripts::add('my_script_handle', __DIR__ .'/assets/js/script.js', ['jquery'], [
        'my_variable' => 'testing this awesome plugin',
    ]);

    /* Enqueue it yourself */
    \EasySCSSandJS\Scripts::add('my_script_handle', __DIR__ .'/assets/js/script.js', ['jquery'], [], false);
    wp_enqueue_script('my_script_handle');

    /* Add the script to the header instead of the footer */
    \EasySCSSandJS\Scripts::add('my_script_handle', __DIR__ .'/assets/js/script.js', ['jquery'], [], true, false);
});

Use variables in SCSS:

// This is recommended. It will throw a fatal error if your PHP doesn't set the variable for some reason.
// If PHP does set it, it will replace $my_cool_color with the defined color in PHP.
$my_cool_color: #ffffff !default;

body{
  background-color: $my_cool_color; // This will be blue (#0000ff)
}

Use variables in JS:

alert(my_script_handle_vars.my_variable);

Compiled files will be saved in wp-content/uploads/compiled-scss-and-js. When that folder is cleared, everything will be regenerated.

Filters

There are filters for adding generic variables to all (or a selection) of scripts and styles or for adding extra content to files:
easy_scss_extra_variables
easy_scss_add_code_before_content
easy_scss_add_code_after_content
easy_scss_create_source_map
easy_scss_storage_folder_name
easy_scss_storage_folder
easy_scss_storage_folder_url
easy_scss_after_compilation
easy_js_extra_variables
easy_js_storage_folder_name
easy_js_storage_folder
easy_js_storage_folder_url
easy_js_after_compilation

使用者評論

閱讀全部 1 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈Easy SCSS and JS〉的開發相關工作。

參與者

將〈Easy SCSS and JS〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

v2.5.7
– Updated scssphp to 1.11.0

v2.5.6
– Updated scssphp to 1.10.5

v2.5.5
– Updated scssphp to 1.10.2

v2.5.4
– Updated scssphp to 1.10.1

v2.5.3
– Removed legacy code

v2.5.1
– Added the easy_css_after_compilation and easy_js_after_compilation filters
– Upgraded scssphp to 1.10.0

v2.5.0
– Added the easy_css_after_compilation and easy_js_after_compilation filters
– Upgraded scssphp to 1.9.0

v2.3.0
– Added the ability to include URLs, which are then cached, minified and served
– Upgraded scssphp to 1.7.0