/**
 * @Author: Bachir Soussi Chiadmi <bach>
 * @Date:   11-04-2017
 * @Email:  bachir@figureslibres.io
 * @Last modified by:   bach
 * @Last modified time: 16-04-2017
 * @License: GPL-V3
 */

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

module.exports = {
  entry: ["./assets/main.js", "./assets/main.scss"],
  output: {
    path: __dirname + "/assets/dist/",
    filename: "main.js"
  },
  devtool: 'source-map',
  module: {
    rules: [
      /* your other rules for JavaScript transpiling go in here */
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['es2015'],
            // plugins: [require('@babel/plugin-proposal-object-rest-spread')]
          }
        }
      },
      {
        // regular css files
        test: /\.css$/,
        use: ExtractTextPlugin.extract({ use: 'css-loader?importLoaders=1', }),
      },
      {
        // sass / scss loader for webpack
        test: /\.(sass|scss)$/,
        use: ExtractTextPlugin.extract(['css-loader', 'sass-loader'])
      },
      {
        // fonts
        test: /\.(eot|svg|ttf|woff|woff2)$/,
        use: "file-loader?name=fonts/[name].[ext]"
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin({
      // define where to save the file
      filename: '[name].css', allChunks: true,
    }),
    new UglifyJsPlugin({
      sourceMap: true,
      parallel:4,
      uglifyOptions: {
        ecma: 8,
        // disable most of compress to gain in compilation speed
        // https://slack.engineering/keep-webpack-fast-a-field-guide-for-better-build-performance-f56a5995e8f1
        compress: {
          arrows: false,
          booleans: false,
          // cascade: false,
          collapse_vars: false,
          comparisons: false,
          computed_props: false,
          hoist_funs: false,
          hoist_props: false,
          hoist_vars: false,
          if_return: false,
          inline: false,
          join_vars: false,
          keep_infinity: true,
          loops: false,
          negate_iife: false,
          properties: false,
          reduce_funcs: false,
          reduce_vars: false,
          sequences: false,
          side_effects: false,
          switches: false,
          top_retain: false,
          toplevel: false,
          typeofs: false,
          unused: false,
          conditionals: false,
          dead_code: true,
          evaluate: false,
          warnings: false
        },
      }
    })
  ],
  watch: true
};
