Socket
Book a DemoInstallSign in
Socket

@funboxteam/scss-vars-loader

Package Overview
Dependencies
Maintainers
4
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@funboxteam/scss-vars-loader

SCSS variables for BEM blocks

latest
Source
npmnpm
Version
2.2.0
Version published
Weekly downloads
125
-56.9%
Maintainers
4
Weekly downloads
 
Created
Source

@funboxteam/scss-vars-loader

npm

Webpack loader that injects $b variable declaration to the processed files with the name of the current BEM block as a value.

По-русски

Rationale

When we develop web apps we use BEM on filesystem. Sometimes blocks become too huge to handle them easily, and when you suddenly need to rename one, you have to rewrite the name in every file. To make it a bit easier we decided to unify block name in SCSS files by $b variable.

At the same time it allows us to generate SCSS files using templates and not to care about the proper name of the selector there.

Getting Started

Install the loader in your project:

npm install --save-dev @funboxteam/scss-vars-loader

Add it into the project's Webpack config so that it is called before sass-loader:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          // ...
          'sass-loader',
          '@funboxteam/scss-vars-loader',
          // ...
        ],
      },
    ],
  },
};

Usage

Use $b to construct SCSS selectors:

.#{$b}__elem_mod_value {
  color: red;
}

Implementation details

At the build stage this line is added into the each processed file:

$b: 'blockname';

To find out the name of the current BEM block properly, the loader goes though the path of the processed file from right to left and searches the first directory name which does not start with _ and uses such directory as a value for $b.

Sponsored by FunBox

FAQs

Package last updated on 27 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts