const path = require('path'),
    webpack = require('webpack'),
    ExtractTextPlugin = require('extract-text-webpack-plugin'),
    LessPluginAutoPrefix = require('less-plugin-autoprefix'),
    LessPluginCleanCSS = require('less-plugin-clean-css'),
    LessPluginGroupCSSMediaQueries =
        require('less-plugin-group-css-media-queries');

module.exports = {
    entry: {
        test: path.resolve(__dirname, '../visual/test.js')
    },

    output: {
        path: path.resolve(__dirname, '../visual'),
        filename: '[name].min.js'
    },

    resolveLoader: {
        modulesDirectories: [ path.join(__dirname, '../../node_modules') ]
    },

    resolve: {
        extensions: ['', '.js', '.less', '.jsx'],
        alias: {
            'atoms': path.resolve(__dirname, '../../atoms'),
            'components': path.resolve(__dirname, '../../components'),
            'web-foundation': path.resolve(__dirname, '..', '..'),
            'transforms': path.resolve(__dirname, '../../transforms')
        }
    },

    devtool: 'eval-cheap-module-source-map',

    module: {
        loaders: [{
            test: /\.less$/,
            exclude: /(node_modules)/,
            loader: ExtractTextPlugin.extract('css?sourceMap!less?{"globalVars":{"theme":"partner"},"sourceMap":true}')
        }, {
            test: /\.(js|jsx)$/,
            exclude: ['node_modules/**/*', '!node_modules/dd/**.*'],
            loader: 'babel-loader',
            query: {
                presets: ['es2015', 'react', 'stage-0']
            }
        }, {
            test: /\.(jpe?g|png|gif|svg)$/i,
            loaders: [
                'file?name=static/img/[hash:8].[ext]',
                'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
            ]
        }, {
            test: /\.(eot|otf|svg|ttf|woff(2)|woff)$/i,
            loader: 'file?name=static/fonts/[hash:8].[ext]',
        } ]
    },

    plugins: [
        new ExtractTextPlugin('./[name].min.css')
    ],

    lessLoader: {
        lessPlugins: [
            LessPluginGroupCSSMediaQueries,
            new LessPluginAutoPrefix({
                browsers: [
                    'last 2 version',
                    'safari 5',
                    'ie 8',
                    'ie 9',
                    'opera 12.1',
                    'ios 6',
                    'android 4'
                ]
            }),
            new LessPluginCleanCSS({
                advanced: true
            })
        ]
    },

    eslint: {
        configFile: path.resolve(__dirname, './lint.json')
    }
};
