Configure project with 1 level
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:
- Remove
layer?from "react-preset" or remove default layer from "naming.cell.stringify". - Deny projects with 1 level (like "bem-react-components") or give simple way to write
bemrcfor them without hacking
@tadatuta tells me that path property can directly point to custom path.
Like:
{
levels: [{ layer: 'common', path: 'blocks' }],
sets: { common: 'common' }
}
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
- Why you trying to use bem-react-components?
- By design you can't use empty layer, it is correct. But you can pass
commonvalue 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 indefaultLayeroption.
- @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"
- 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?