const {getLoaderAbsolutePath} = require('./utils');

const cssLoaders = function (options) {
    options = options || {};

    var cssLoader = {
        loader: getLoaderAbsolutePath('css-loader'),
        options: {
            minimize: process.env.NODE_ENV === 'production',
            sourceMap: options.sourceMap
        }
    };

    // generate loader string to be used with extract text plugin
    function generateLoaders(loader, loaderOptions) {
        var loaders = [cssLoader];
        if (loader) {
            loaders.push({
                loader: loader + '-loader',
                options: Object.assign({}, loaderOptions, {
                    sourceMap: options.sourceMap
                })
            });
        }

        // Extract CSS when that option is specified
        // (which is the case during production build)
        // if (options.extract) {
        //     return ExtractTextPlugin.extract({
        //         use: loaders,
        //         fallback: 'vue-style-loader'
        //     });
        // } else {
        return ['vue-style-loader'].concat(loaders);
        // }
    }

    // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
    return {
        css: generateLoaders(),
        postcss: generateLoaders(),
        less: generateLoaders('less'),
        sass: generateLoaders('sass', {
            indentedSyntax: true
        }),
        scss: generateLoaders('sass'),
        stylus: generateLoaders('stylus'),
        styl: generateLoaders('stylus')
    };
};

module.exports = {
    transformAssetUrls: {
        'b-image': 'src'
    },
    loaders: cssLoaders({
        sourceMap: false,
        extract: false
    }),
    postcss: [
        require('autoprefixer')({
            overrideBrowserslist: ['iOS >= 7', 'Android >= 4.1']
        })
    ]
};
