bem-sdk icon indicating copy to clipboard operation
bem-sdk copied to clipboard

Configure project with 1 level

Open Vittly opened this issue 7 years ago • 4 comments

bem-react-components is good example of project with 1 level. For now it has only "blocks" directory for all components and have no bemrc. My project uses "bem-react-components". I want to build it with webpack-bem-plugin. "webpack-bem-plugin" needs from all libraries to have its bemrc. So I had to write it for "bem-react-components"

My knowledge base:

  • "react-preset" transforms empty layer string to "blocks" directory: code here
  • "bem/sdk.config" can resolve set item to library layer: proof. Can we remove it? It is prohibited at index.js)
  • "bem/sdk.config" takes any non string set value as is: code

My attempt:

// bem-react-components/.bemrc
{
  levels: [
    // some nasty hacking#1 with empty layer
    { layer: '', naming: 'react' }
  ],
  sets: {
    // if set value is not a string we can do more hacking#2
    common: { layer: '' }
  }
}

// my project .bemrc
{
  levels: [...],
  sets: {
    touch: 'common@bem-react-components common touch'
  }
}

It is not working because of you cannot simply pass empty layer.

My suggestions:

  1. Remove layer? from "react-preset" or remove default layer from "naming.cell.stringify".
  2. Deny projects with 1 level (like "bem-react-components") or give simple way to write bemrc for them without hacking

Vittly avatar Mar 13 '18 15:03 Vittly

@tadatuta tells me that path property can directly point to custom path.

Like:

{
  levels: [{ layer: 'common', path: 'blocks' }],
  sets: { common: 'common' }
}

Vittly avatar Mar 16 '18 12:03 Vittly

This approach will fail when BemCell will be stringified with preset. We will get something like "blocks/common.blocks". Besides level defined with path property is deprecated

Vittly avatar Mar 17 '18 18:03 Vittly

@Vittly

  1. Why you trying to use bem-react-components?
  2. By design you can't use empty layer, it is correct. But you can pass common value and make it after stringifying empty (along with dot) like it does in tests for schemes with @{layer} suffix: https://github.com/bem/bem-sdk/blob/master/packages/naming.cell.stringify/test/cell-stringify.test.js#L71-L79 — just pass in defaultLayer option.

qfox avatar Mar 20 '18 23:03 qfox

  1. @veged sends me in this direction (actually wrong one). Our projects should use another library I understand that now. We've planned to migrate from "bem-react-components"
  2. Hmm "defaultLayer" seems good (anyway I should define custom naming). So right form of "bemrc" for "bem-react-components" is:
{
  naming: {
    basedOn: 'react',
    fs: { patter: 'blocks/${entity}.${tech}' }
  },
  levels: [{ layer: 'common', path: 'blocks' }],
  sets: {
    common: 'common'
  }
}

Yes?

Vittly avatar Mar 21 '18 10:03 Vittly