const config = require('./webpack.config');
const options = require('./webpack.config.options');
const StyleLintPlugin = require('stylelint-webpack-plugin');

module.exports = function(env) {
    const generatedConfig = config(env, false);
    delete generatedConfig.devtool;

    generatedConfig.plugins = [
        new StyleLintPlugin({
            configFile: '.stylelintrc',
            context: 'src',
            emitErrors: true,
            failOnError: true,
            quiet: false,
        }),
    ].concat(options.getPlugins(env || {}));

    return generatedConfig;

    // Lesman 9/29/2017
    // I thought this might make stuff faster?
    // but it doesn't seem to

    // var rules = generatedConfig.module.rules;
    // for (var i = 0; i < rules.length; i++) {
    //     var use = rules[i].use;
    //     for (var j = 0; j < use.length; j++) {
    //         var loader = use[j];
    //         if (loader === 'source-map-loader') {
    //             use.splice(j);
    //             j--;
    //             continue;
    //         }
    //         if (loader.options !== undefined) {
    //             if (loader.options.sourceMap !== undefined) {
    //                 loader.options.sourcemap = false;
    //             }
    //         }
    //     }
    // }
}
