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


const srcPath = path.join(__dirname, 'src');
const srcJsPath = path.join(srcPath, 'js');

const destPath = path.join(__dirname, 'dist');
const destJsPath = path.join(destPath, 'js');

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

const env = process.env.NODE_ENV || 'production';

const config = {
    watch: env !== 'production',
    entry: {
        "shared": srcJsPath + '/shared',
    },
    output: {
        path: destJsPath,
        filename: '[name].js'
    },
    module: {
        rules: [
            {
              test: /\.js$/,
              exclude: /(node_modules|bower_components)/,
              use: {
                loader: 'babel-loader',
                options: {
                  presets: ['es2015']
                }
              }
            }
          ]
    },
    stats: {
        colors: true
    },
    plugins: []
}

if (env === 'production') {
    config.plugins.push(
        new UglifyJsPlugin()
    )
}

module.exports = config;