dnafactory/module-scss

Provides an scss preprocessor to Magento 2

Installs: 1 792

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 0

Open Issues: 0

Type:magento2-module

1.1.2 2022-05-25 14:07 UTC

This package is auto-updated.

Last update: 2024-04-25 18:40:40 UTC


README

License

Provides an Scss preprocessor (scssphp/scssphp) to Magento 2 as an Alternative Source Content Processor.

Supports Magento 2 Theme inheritance and Assets fallback system.

Frontend compilation is currently not tested and not fully implemented yet.

How to use

Put your base scss file in your preferred location as Magento 2 standards. Ex:

  • app/design/frontend/MyCompany/theme/web/css/--->mystyle.scss
  • app/code/MyCompany/MyModule/view/frontend/web/css/--->mystyle.scss
  • app/design/frontend/MyCompany/theme/TheirCompany_TheirModule/web/css/--->mystyle.scss

Then add your source files references as you do with .less ones. Oh, and you can use Magento custom directives (like @magento_import) too. Ex:

@import 'source/_mixins';
@import 'source/functions.scss';
//@magento_import 'source/_extends.scss';

The @vars_import directive

As Magento 2 comes only with .less preprocessor, you may need to merge your new shiny scss project into the old fashioned .less theme. When it comes to needs, you can simply use the @vars_import directive on top of your main scss file to load and translate .less vars. Ex:

//@vars_import 'source/_variables.less';

@import 'source/_mixins';
@import 'source/functions.scss';
//@magento_import 'source/_extends.scss';

All less variables will be translated into scss readable ones, so you can then reference them in your scss subsequent assets.

Ex: @primary__color will be accessible as $primary__color

When you are coding in a module context you may need to import Magento 2 .less lib vars. Therefore, to avoid context issues, it may come in handy to use the @vars_import directive with the addition of the (lib) identifier. Ex:

//@vars_import (lib) 'source/lib/_lib.less'

Happy Coding