'use strict';
const path = require('path');
const config = require('../config');

exports.assetsPath = function (_path) {
  const assetsSubDirectory = process.env.NODE_ENV === 'production'
    ? config.build.assetsSubDirectory
    : config.dev.assetsSubDirectory;
  return path.posix.join(assetsSubDirectory, _path)
};

exports.generateLoaders=function(loader) {
    var _loader = null;
    if (loader && loader !== 'css') {
        _loader = loader + '-loader';
    }

    if(loader==='styl'){
      _loader='stylus';
    }

    var use = [
        'style-loader', {
            loader: 'css-loader?minimize',
            options: {
                importLoaders: 1
            }
        }, {
            loader: 'postcss-loader',
            options: {
                ident: 'postcss',
                plugins: (loader) => [
                    require('autoprefixer')({
                        broswers: ['last 5 versions']
                    })
                ]
            }
        }
    ];

    if(_loader){
        use.push(_loader);
    }

    return {
        test: new RegExp('\\.' + loader + '$'),
        use:use
    }
};
