var path = require('path'),
    glob = require('glob'),
    _ = require('lodash'),
    combine = require('stream-combiner');

module.exports = function setupCSSPipeline(gulp) {
  var CHECK_PLUGINS,
      PROCESS_PLUGINS;

  function getPostCSSPlugins(pluginList, pluginOptions) {
    return _.map(pluginList, function requirePluginWithOptions(plugin) {
      var options = _.get(pluginOptions, plugin);
      return require(plugin)(options);
    });
  }

  CHECK_PLUGINS = [
    'stylelint',
    'reporter-plus/postcss'
  ];

  PROCESS_PLUGINS = [
    // Sass-style convenience
    'postcss-import',
    'postcss-mixins',
    'postcss-nested',
    'postcss-simple-vars',

    // Reduce calcs, when possible
    'postcss-calc',

    // Grid system
    'lost',

    // Sane loops
    'postcss-each',
    'postcss-for',

    // Additional functions
    'postcss-color-function',

    // New selectors
    'postcss-selector-matches',
    'postcss-selector-not',

    // Some niceties
    'postcss-easings',
    'postcss-clearfix',

    // Browser compat
    'autoprefixer',
    'postcss-pseudoelements',
    'postcss-color-rgba-fallback'
  ];

  return function cssPipeline(options) {
    var importIDs = {};

    options = _.defaultsDeep({}, options, {
      doCheck: true,
      doProcessing: true,
      doMinify: false,
      doConcat: false,
      doBanner: false,
      doVersioning: false,
      doSourceMaps: true,

      concatName: 'override_me.css',
      banner: '/* Built: ' + Date.now() + ' */\n',
      mapsDir: '.maps',

      postCSSOptions: {
          parser: require('postcss-scss')
        },
      pluginOptions: {
          stylelint: {
              rules: require('../../runcoms/rc.stylelint.json')
            },
          'postcss-import': {
              plugins: [
                  require('postcss-discard-comments')
                ],
              transform: function (fileContents) {
                  // This allows us to use //-style comments in imported files, since
                  // PostCSS-import doesn't allow non-css syntaxes in its parser
                  return fileContents.replace(/\/\/\s(.*)\n/g, '/* $1 */\n');
                },
              resolve: function (id, baseDir, options) {
                  var files,
                      pattern = id,
                      globOptions = {
                          cwd: options.path[0],
                          nosort: true
                        },
                      bowerSearch;

                  if (importIDs[id]) {
                    return importIDs[id];
                  }

                  // Look for a bower package
                  bowerSearch = /^(.+):(.+)$/.exec(id);

                  if (!!bowerSearch) {
                    pattern = bowerSearch[2];
                    globOptions.cwd = path.join(options.root, 'bower_components', bowerSearch[1]);
                  }

                  files = glob.sync(path.join('**', pattern), globOptions);

                  if (files.length) {
                    files = _.map(files, function addRoot(filepath) {
                      return path.join(globOptions.cwd, filepath);
                    });

                    importIDs[id] = files;

                    return files;
                  } else {
                    return [];
                  }
                }
            },
          'postcss-simple-vars': {
              silent: true
            }
        },
      minifyOptions: {
          reduceIdents: false,
          mergeIdents: false,
          discardUnused: false,
          zindex: false
        },
      minifyRenameOptions: {
          extname: '.min.css'
        }
    });

    return combine(_.compact([
        // Checking pipeline
        options.doCheck && require('gulp-postcss')(
            getPostCSSPlugins(CHECK_PLUGINS, options.pluginOptions),
            options.postCSSOptions
          ),

        // Processing pipeline
        options.doSourceMaps && require('gulp-sourcemaps').init(),
        options.doProcessing && require('gulp-postcss')(
            getPostCSSPlugins(PROCESS_PLUGINS, options.pluginOptions),
            options.postCSSOptions
          ),

        // Productionization pipeline
        options.doMinify && require('gulp-cssnano')(options.minifyOptions),
        options.doConcat && require('gulp-concat')(options.concatName),
        options.doBanner && require('gulp-header')(options.banner),
        options.doVersioning && require('gulp-rev')(),
        options.doMinify && require('gulp-rename')(options.minifyRenameOptions),
        options.doSourceMaps && require('gulp-sourcemaps').write(options.mapsDir)
    ]));
  };
};

@@ -2463,29 +2463,27 @@
             
-bower
+ext
 Search;%0A%0A   
@@ -2612,22 +2612,26 @@
 ok for a
- bower
+n external
  package
@@ -2649,21 +2649,19 @@
         
-bower
+ext
 Search =
@@ -2710,21 +2710,19 @@
   if (!!
-bower
+ext
 Search) 
@@ -2753,21 +2753,19 @@
 ttern = 
-bower
+ext
 Search%5B2
@@ -2828,16 +2828,58 @@
 ns.root,
+ _.get(gulp, 'webToolsConfig.ext.modules',
  'bower_
@@ -2893,15 +2893,14 @@
 nts'
+)
 , 
-bower
+ext
 Sear

Allow using npm for external CSS references