Войти с помощью github
Форум /

Чтобы при сборки в desktop версию падали файлы из desktop.blocks, а в touch соответственно из touch.blocks. Ну и common.blocks был общим.

var fs = require('fs'),
  path = require('path'),
  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'),
  merged = require('./techs/merged'),
  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'
  ];

module.exports = function(config) {
  var isProd = process.env.YENV === 'production',
    mergedBundleName = 'merged',
    pathToMargedBundleDesktop = path.join('desktop.bundles', mergedBundleName),
    pathToMargedBundleTouch = path.join('touch.bundles', mergedBundleName);

  fs.existsSync(pathToMargedBundleDesktop) || fs.mkdirSync(pathToMargedBundleDesktop);
  fs.existsSync(pathToMargedBundleTouch) || fs.mkdirSync(pathToMargedBundleTouch);

  merged(config, pathToMargedBundleDesktop);
  merged(config, pathToMargedBundleTouch);

  config.nodes('*.bundles/*', function(nodeConfig) {
    var isMergedNode = path.basename(nodeConfig.getPath()) === mergedBundleName;

    isMergedNode || nodeConfig.addTechs([
      [techs.fileProvider, {target: '?.bemjson.js'}],
      [enbBemTechs.bemjsonToBemdecl]
    ]);

    nodeConfig.addTechs([
      // essential
      [enbBemTechs.levels, {levels: levels}],
      [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', minify: isProd}],
      [techs.borschik, {source: '?.css', target: '?.min.css', tech: 'cleancss', minify: isProd}]
    ]);

    nodeConfig.addTargets([/* '?.bemtree.js', */ '?.min.css', '?.min.js']);
    isMergedNode || nodeConfig.addTargets(['?.html']);
  });
};