Closed nullablemind closed 8 years ago
Не получается настроить. Пытаюсь настроить обе сборки.
'use strict';
var techs = {
// essential
fileProvider: require('enb/techs/file-provider'),
fileMerge: require('enb/techs/file-merge'),
// optimization
borschik: require('enb-borschik/techs/borschik'),
// css
stylus: require('enb-stylus/techs/stylus'),
// js
browserJs: require('enb-js/techs/browser-js'),
// bemtree
// bemtree: require('enb-bemxjst/techs/bemtree'),
// bemhtml
bemhtml: require('enb-bemxjst/techs/bemhtml'),
bemjsonToHtml: require('enb-bemxjst/techs/bemjson-to-html')
},
enbBemTechs = require('enb-bem-techs'),
levels = [
{path: 'libs/bem-core/common.blocks', check: false},
{path: 'libs/bem-core/desktop.blocks', check: false},
{path: 'libs/bem-components/common.blocks', check: false},
{path: 'libs/bem-components/desktop.blocks', check: false},
{path: 'libs/bem-components/design/common.blocks', check: false},
{path: 'libs/bem-components/design/desktop.blocks', check: false},
{path: 'libs/bem-forms/common.blocks', check: false},
'common.blocks',
'desktop.blocks'
],
fs = require('fs'),
path = require('path'),
platforms = ['desktop'];
module.exports = function(config) {
var isProd = process.env.YENV === 'production';
config.nodes('*.bundles/*', function(nodeConfig) {
nodeConfig.addTechs([
// essential
[enbBemTechs.levels, {levels: levels}],
[techs.fileProvider, {target: '?.bemjson.js'}],
[enbBemTechs.bemjsonToBemdecl],
[enbBemTechs.deps],
[enbBemTechs.files],
// css
[techs.stylus, {
target: '?.css',
sourcemap: false,
autoprefixer: {
browsers: ['ie >= 10', 'last 2 versions', 'opera 12.1', '> 2%']
}
}],
// bemtree
// [techs.bemtree, { sourceSuffixes: ['bemtree', 'bemtree.js'] }],
// bemhtml
[techs.bemhtml, {sourceSuffixes: ['bemhtml', 'bemhtml.js']}],
// html
[techs.bemjsonToHtml],
// client bemhtml
[enbBemTechs.depsByTechToBemdecl, {
target: '?.bemhtml.bemdecl.js',
sourceTech: 'js',
destTech: 'bemhtml'
}],
[enbBemTechs.deps, {
target: '?.bemhtml.deps.js',
bemdeclFile: '?.bemhtml.bemdecl.js'
}],
[enbBemTechs.files, {
depsFile: '?.bemhtml.deps.js',
filesTarget: '?.bemhtml.files',
dirsTarget: '?.bemhtml.dirs'
}],
[techs.bemhtml, {
target: '?.browser.bemhtml.js',
filesTarget: '?.bemhtml.files',
sourceSuffixes: ['bemhtml', 'bemhtml.js']
}],
// js
[techs.browserJs, {includeYM: true}],
[techs.fileMerge, {
target: '?.js',
sources: ['?.browser.js', '?.browser.bemhtml.js']
}],
// borschik
[techs.borschik, {source: '?.js', target: '?.min.js'}],
[techs.borschik, {source: '?.css', target: '?.min.css', tech: 'cleancss'}]
]);
nodeConfig.addTargets([/* '?.bemtree.js', */ '?.html', '?.min.css', '?.min.js']);
});
// Создаем директории для merged-бандлов (1)
platforms.forEach(function(platform) {
var node = path.join(platform + '.bundles', 'merged');
if (!fs.existsSync(node)) {
fs.mkdirSync(node);
}
});
// Предоставляем BEMDECL-файлы из бандлов (2)
config.nodes('*.bundles/*', function(nodeConfig) {
var node = path.basename(nodeConfig.getPath());
if (node !== 'merged') {
nodeConfig.addTechs([
[techs.fileProvider, {target: '?.bemdecl.js'}]
]);
}
});
// Настраиваем сборку merged-бандла
config.nodes('*.bundles/merged', function(nodeConfig) {
var dir = path.dirname(nodeConfig.getPath()),
bundles = fs.readdirSync(dir),
bemdeclFiles = [];
// Копируем BEMDECL-файлы в merged-бандл (3)
bundles.forEach(function(bundle) {
if (bundle === 'merged') return;
var node = path.join(dir, bundle),
target = bundle + '.bemdecl.js';
nodeConfig.addTech([techs.provideBemdecl, {
node: node,
target: target
}]);
bemdeclFiles.push(target);
});
// Объединяем скопированные BEMDECL-файлы (4)
nodeConfig.addTech([techs.mergeBemdecl, {sources: bemdeclFiles}]);
// Обычная сборка бандла (5)
nodeConfig.addTechs([
[techs.levels, {levels: ['desktop.blocks']}],
[techs.deps],
[techs.files],
[stylus],
[browserJs]
]);
nodeConfig.addTargets(['?.css', '?.js']);
});
};
@antonazgarovich вот дифф для project-stub
, включающий сборку merged-бандла: https://github.com/bem/project-stub/compare/merged?expand=1
@tadatuta Спасибо все работает!
Как это можно сделать?