{"id":14990677,"url":"https://github.com/fakundo/bem-classnames-loader","last_synced_at":"2026-02-23T08:34:52.662Z","repository":{"id":74039850,"uuid":"63452980","full_name":"fakundo/bem-classnames-loader","owner":"fakundo","description":"Use BEM class names defined in your css files","archived":false,"fork":false,"pushed_at":"2016-12-01T14:32:03.000Z","size":43,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T19:46:01.796Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fakundo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-15T21:55:02.000Z","updated_at":"2018-01-25T22:02:38.000Z","dependencies_parsed_at":"2023-03-11T16:23:55.152Z","dependency_job_id":null,"html_url":"https://github.com/fakundo/bem-classnames-loader","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"de7fe07afa9d65e13b3a1ace77a8f49967a2527e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakundo%2Fbem-classnames-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakundo%2Fbem-classnames-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakundo%2Fbem-classnames-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakundo%2Fbem-classnames-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fakundo","download_url":"https://codeload.github.com/fakundo/bem-classnames-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244888647,"owners_count":20526849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T14:20:34.628Z","updated_at":"2025-10-27T22:07:29.185Z","avatar_url":"https://github.com/fakundo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#bem-classnames-loader for webpack\n\n[![npm](https://img.shields.io/npm/v/bem-classnames-loader.svg?maxAge=2592000)](https://www.npmjs.com/package/bem-classnames-loader)\n\nThis loader extracts modifiers and states defined in your css files and then provide an interface for generating class names. So you get a something similar with css-modules but with BEM.\n\n##Installation\n```\nnpm install bem-classnames-loader --save-dev\n```\n\n##Examples\n\nbutton.scss\n```scss\n.button {\n  color: white;\n  cursor: pointer;\n\n  \u0026__inner {\n    font-size: 16px;\n  }\n\n  \u0026--borderless {\n    border: none;\n  }\n\n  \u0026--type-default {\n    background-color: gray;\n  }\n\n  \u0026--type-success {\n    background-color: green;\n  }\n\n  \u0026.is-disabled {\n    opacity: .5;\n    cursor: default;\n  }\n}\n```\n\nbutton.js\n```js\nimport style from './button.scss';\n\nstyle('button') // button\nstyle('button', { disabled: true }) // button is-disabled\nstyle('button', { borderless: true }) // button button--borderless\nstyle('button', { disabled: true, type: 'success' }) // button is-disabled button--type-success\nstyle('button', { disabled: true }, 'form__button') // button is-disabled form__button\nstyle('button', { disabled: true }, { type: 'default' }, 'form__button') // button is-disabled button--type-default form__button\n\nstyle('\u0026') // button\nstyle('\u0026inner') // button__inner\nstyle('button__inner') // button__inner\n```\n\nwebpack.config.js\n```js\n...\n// Optional parameters (you can pass them with loader query too)\nbemClassnames: {\n  prefixes: {\n    state: 'is-'\n  }\n},\nmodule: {\n  loaders: [\n    {\n      test: /\\.scss$/,\n      loader: 'bem-classnames!style!css!sass'\n\n      // If you using extract-text-plugin\n      // loaders: ['bem-classnames', ExtractTextPlugin.extract('css!sass')]\n    }\n  ]\n}\n...\n```\n\n##React component example\nThis example shows how easy you can use props to generate class names. \n\n```js\nimport React, { Component, PropTypes } from 'react';\nimport style from './button.scss';\n\nexport default class Button extends Component {\n    \n  static propTypes = {\n    disabled: PropTypes.bool,\n    borderless: PropTypes.bool,\n    type: PropTypes.oneOf([ 'success', 'default' ]);\n  };\n\n  static defaultProps = {\n    type: 'default'\n  };\n\n  render() {\n    return (\n      \u003cbutton className={style('\u0026', this.props)}\u003e\n        \u003cdiv className={style('\u0026inner')}\u003e\n          Click me\n        \u003c/div\u003e\n      \u003c/button\u003e\n    );\n  }\n  \n};\n```\n\nNow render `Button` with different props:\n\n```js\n\u003cButton /\u003e //button button--type-default\n\u003cButton borderless /\u003e //button button--type-default button--borderless\n\u003cButton type=\"success\" /\u003e //button button--type-success\n\u003cButton type=\"success\" disabled /\u003e //button button--type-success is-disabled\n```\n\n\u003ca name=\"loader-options\"\u003e\u003c/a\u003e\n##Loader options\n\n```js\n{\n  prefixes: {\n    element: '__',\n    modifier: '--',\n    state: 'is-',\n    modifierValue: '-',\n    stateValue: '-'\n  },\n  applyClassPrefix: ''\n}\n```\n\n- `prefixes` - define bem entity prefixes\n- `applyClassPrefix` - prefix will be added to class names. For example, you use `postcss-loader` and it's `postcss-class-prefix` plugin to add prefixes in your css. So you should use `applyClassPrefix` to add prefixes on Javascript side.\n\n##API \n```js\nimport style from './button.scss';\n```\n##`style` \nItself is a function, which generates class names in cool way.\n\n##`style.ns` \nGet/set namespace. Sometimes class name is very large, namespaces help you to write lesser code.\n\nExample:\n```js\nstyle('\u0026') // button\nstyle('\u0026inner') // button__inner\n\n// Set new namespace if you need\nstyle.ns('super-good-component');\n\nstyle('\u0026') // super-good-component\nstyle('\u0026placeholder') // super-good-component__placeholder\n```\n\n##`style.modifier`\nAdds new modifier.\n\nExample: \n```js\n// Add boolean modifier\nstyle.modifier('button', 'fade');\nstyle('button', { fade: true }) // button button--fade\n\n// Add string modifier\nstyle.modifier('button', 'size', ['sm', 'lg']);\nstyle('button', { size: 'sm' }) // button button--size-sm\n```\n\n##`style.state`\nAdds new state.\n\nExample: \n```js\n// Add boolean state\nstyle.state('button', 'active');\nstyle('button', { active: true }) // button is-active\n\n// Add string state\nstyle.state('button', 'foo', ['bar']);\nstyle('button', { foo: 'bar' }) // button is-foo-bar\n```\n\n##`style.getClasses` \nReturns defined classes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakundo%2Fbem-classnames-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffakundo%2Fbem-classnames-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakundo%2Fbem-classnames-loader/lists"}