var webpack = require('webpack');
var path = require('path');


// Naming and path settings
var entryPoint = './src/main.js';
var exportPath = path.resolve(__dirname, './build');

// Enviroment flag
var plugins = [];
var env = process.env.WEBPACK_ENV;

// Differ settings based on production flag
if (env === 'production') {
    var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;

    plugins.push(new UglifyJsPlugin({
        minimize: true,
        sourceMap: true
    }
    ));
    plugins.push(new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: '"production"'
        }
    }
    ));

}

// Main Settings config
module.exports = {
    entry: [
        'intersection-observer',
        'babel-polyfill',
        entryPoint
    ],
    devtool: 'source-map',
    output: {
        path: exportPath,
        publicPath: 'build/',
        filename: '[name].bundle.js',
        chunkFilename: '[name].bundle.js'
    },
    module: {
        loaders: [{
            enforce: "pre",
            test: /\.(vue|js)$/,
            loader: 'eslint-loader',
            exclude: /node_modules/
        }, {
            test: /\.(jpe?g|png|gif|woff|woff2|ttf|svg|eot)(\?.*)?$/i,
            loader: 'file-loader',
            options: {
                name: '[name].[sha512:hash:base64:7].[ext]'
            }
        }, {
            test: /\.vue$/,
            loader: 'vue-loader'
        }, {
            test: /\.js$/,
            exclude: /(node_modules|bower_components)/,
            loader: 'babel-loader',
            query: {
                presets: ['es2015'],
                plugins: ['syntax-dynamic-import']
            }
        }]
    },
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        },
        modules: [path.resolve(__dirname, "src"), "node_modules"],
        extensions: [".vue", ".js", ".less"]
    },
    plugins
};