Last active
September 30, 2016 02:57
-
-
Save qfox/9ebf44c7da17e233ff660d902ba04d36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const gulp = require('gulp'); | |
const debug = require('gulp-debug'); | |
const Builder = require('gulp-bem-bundle-builder'); | |
const bundler = require('gulp-bem-bundler-fs'); | |
const postcss = require('gulp-postcss'); | |
const postcssUrl = require('postcss-url'); | |
const autoprefixer = require('autoprefixer'); | |
const csso = require('gulp-csso'); | |
const filter = require('through2-filter').obj; | |
const merge = require('merge2'); | |
const concat = require('gulp-concat'); | |
const stylus = require('gulp-stylus'); | |
const uglify = require('gulp-uglify'); | |
const bemhtml = require('gulp-bem-xjst').bemhtml; | |
const builder = Builder({ | |
levels: [ | |
'libs/bem-core/common.blocks', | |
'libs/bem-core/desktop.blocks', | |
'libs/bem-components/common.blocks', | |
'libs/bem-components/desktop.blocks', | |
'libs/bem-components/design/common.blocks', | |
'libs/bem-components/design/desktop.blocks', | |
'common.blocks', | |
'desktop.blocks' | |
], | |
techMap: { | |
bemhtml: ['bemhtml.js'], | |
js: ['vanilla.js', 'browser.js', 'js'], | |
css: ['styl', 'css'] | |
} | |
}); | |
gulp.task('build', () => { | |
return bundler('*.bundles/*') | |
.pipe(builder({ | |
css: bundle => | |
bundle.src('css') | |
.pipe(stylus()) | |
.pipe(postcss([ | |
autoprefixer({ | |
browsers: ['ie >= 10', 'last 2 versions', 'opera 12.1', '> 2%'] | |
}), | |
postcssUrl({ url: 'inline' }) | |
])) | |
.pipe(csso()) | |
.pipe(concat(bundle.name + '.min.css')), | |
js: bundle => | |
merge( | |
gulp.src(require.resolve('ym')), | |
bundle.src('js').pipe(filter(f => ~['vanilla.js', 'browser.js', 'js'].indexOf(f.tech))), | |
bundle.src('js').pipe(filter(f => f.tech === 'bemhtml.js')) | |
.pipe(concat('browser.bemhtml.js')).pipe(bemhtml()) | |
) | |
.pipe(uglify()) | |
.pipe(concat(bundle.name + '.min.js')), | |
bemhtml: bundle => | |
bundle.src('bemhtml') | |
.pipe(concat('any.bemhtml.js')) | |
.pipe(bemhtml()) | |
.pipe(concat(bundle.name + '.bemhtml.js')) | |
})) | |
.on('error', console.error) | |
.pipe(debug()) | |
.pipe(gulp.dest(file => path.dirname(file.path))); | |
}); | |
gulp.task('default', gulp.series('build')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment