Skip to content

Instantly share code, notes, and snippets.

@belozer
Last active November 24, 2016 14:49
Show Gist options
  • Save belozer/7c2f3448f67caca79f76845a77d4e0e1 to your computer and use it in GitHub Desktop.
Save belozer/7c2f3448f67caca79f76845a77d4e0e1 to your computer and use it in GitHub Desktop.
Gulpfile with gulp-bem-presets
const gulp = require('gulp');
const Builder = require('gulp-bem-bundle-builder');
const bundler = require('gulp-bem-bundler-fs');
const nodemon = require('gulp-nodemon');
const merge = require('merge2');
const debug = require('gulp-debug');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const gulpif = require('gulp-if');
const concat = require('gulp-concat');
const env = process.env.NODE_ENV
const builder = Builder({
levels: [
'bem/libs/bem-core/common.blocks',
'bem/libs/bem-core/desktop.blocks',
'bem/libs/bem-components/common.blocks',
'bem/libs/bem-components/desktop.blocks',
'bem/libs/bem-components/design/common.blocks',
'bem/libs/bem-components/design/desktop.blocks',
'bem/libs/bem-forms/common.blocks',
'bem/libs/bem-animations/@common',
'bem/libs/bem-animations/@bem-core-v4',
'bem/blocks/@common/',
'bem/blocks/@desktop/',
],
techMap: {
bemtree: ['bemtree.js'],
bemhtml: ['bemhtml.js'],
js: ['js', 'vanilla.js', 'source.js', 'browser.js'],
css: ['styl', 'css', 'post.css']
}
});
gulp.task('build', () => {
return bundler('bem/bundles/*')
.pipe(builder({
// Styles
css: bundle =>
require('gulp-bem-preset-css')(bundle, {svgPaths: ['bem/icons']}),
// client JS, BEMTREE, BEMHTML
js: bundle => merge(
require('gulp-bem-preset-browserjs')(bundle, {includePaths: ['bem']}),
require('gulp-bem-preset-bemtree')(bundle, {ym: true}),
require('gulp-bem-preset-bemhtml')(bundle, {ym: true, engine: {elemJsInstances: true}})
)
.pipe(gulpif(env === 'production', babel({ presets: ['es2015'], compact: false })))
.pipe(gulpif(env === 'production', uglify()))
.pipe(concat(bundle.name + '.min.js')),
// server BEMTREE
bemtree: bundle =>
require('gulp-bem-preset-bemtree')(bundle)
.pipe(gulp.dest('./bem/server/')),
// server BEMHTML
bemhtml: bundle =>
require('gulp-bem-preset-bemhtml')(bundle)
.pipe(gulp.dest('./bem/server/'))
}))
.on('error', console.error)
.pipe(debug())
.pipe(gulp.dest('./public/bundles/'));
});
gulp.task('default', gulp.series('build'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment