PostHTML plugin for support to simplify the maintenance of BEM naming structure in html
$ npm install --save-dev posthtml-bem
##Features
<div block="MadTeaParty">
Mad Tea Party
</div>
This would render like
<div class="MadTeaParty">
Mad Tea Party
</div>
<div block="MadTeaParty">
<div element="march_hare">March Hare</div>
</div>
This would render like
<div class="MadTeaParty">
<div class="MadTeaParty__march_hare">March Hare</div>
</div>
Attention: Please use "mods" for the attribute modifiers instead of "mod" and a space as a separator of modifiers instead of a comma.
<div block="MadTeaParty">
<div element="march_hare" mod="mad">March Hare</div>
</div>
This would render like
<div class="MadTeaParty">
<div class="MadTeaParty__march_hare MadTeaParty__march_hare--mad">
March Hare
</div>
</div>
Native classes are supplemented by BEM classes
<div block="animal" class="clearfix grid">
<div element="nose" mod="long" class="clearfix grid">Nose</div>
</div>
This would render like
<div class="animal clearfix grid">
<div class="animal__nose animal__nose--long clearfix grid">Nose</div>
</div>
var posthtml = require('posthtml'),
config = {
elemPrefix: '__',
modPrefix: '--'
},
html = '<div block="mad-tea-party"><div element="march_hare" mod="mad">March Hare</div><div element="hatter" mod="type:mad">Hatter</div><div element="dormouse" mod="sleepy">Dormouse</div></div>';
posthtml()
.use(require('posthtml-bem')(config))
.process(html)
.then(function (result) {
console.log(result.html);
});
let config = {
...
module: {
rules: [
{
test: /\.html/,
use: [
{
loader: 'html-loader',
options: {
minimize: false
}
},
{
loader: 'posthtml-loader',
options: {
ident: 'posthtml',
plugins: [
require('posthtml-bem')()
]
}
}
]
}
...
};
module.exports = config;
var gulp = require('gulp'),
rename = require('gulp-rename'),
posthtml = require('gulp-posthtml');
gulp.task('default', function () {
return gulp.src('before.html')
.pipe(posthtml([
require('posthtml-bem')({
elemPrefix: '__',
modPrefix: '--'
})
]))
.pipe(rename('after.html'))
.pipe(gulp.dest('.'));
});
jade template
div(block='animals')
div(element='rabbit' mod='scurrying white')
div(element='dormouse' mod='sleeper red')
This plugin was inspired by the syntax and the idea of using custom attributes from BEML and bemto. This is a fork of rajdee/posthtml-bem
MIT