text: 'use strict';
  
  const Path = require('path');
  const Webpack = require('webpack');
  const HtmlWebpackPlugin = require('html-webpack-plugin');
  const ExtractTextPlugin = require('extract-text-webpack-plugin');
  const ExtractSASS = new ExtractTextPlugin('styles/bundle.css');
  
  module.exports = (options) => {
  
    let webpackConfig = {
      devtool: options.devtool,
      entry: [
        `webpack-dev-server/client?http://localhost:${options.port}`,
        'webpack/hot/dev-server',
        './src/scripts/index'
      ],
      output: {
        path: Path.join(__dirname, 'dist'),
        filename: 'bundle.js'
      },
      resolve: {
          extensions: ['', '.js'],
          alias: {
            webworkify: 'webworkify-webpack',
            'mapbox-gl': Path.resolve('./node_modules/mapbox-gl/dist/mapbox-gl.js')
          }
        },
      plugins: [
        new Webpack.DefinePlugin({
          'process.env': {
            NODE_ENV: JSON.stringify(options.isProduction ? 'production' : 'development')
          }
        }),
        new HtmlWebpackPlugin({
          template: './src/index.html'
        })
      ],
      module: {
        loaders: [{
          test: /\.js$/,
          exclude: /(node_modules|bower_components)/,
          loader: 'babel',
          query: {
            presets: ['es2015']
          }
        }, {
          test: /mapbox-gl.+\.js$/,
          loader: 'transform/cacheable?brfs'
        }]
      }
    };
  
    if (options.isProduction) {
      webpackConfig.entry = ['./src/scripts/index'];
  
      webpackConfig.plugins.push(
        new Webpack.optimize.OccurenceOrderPlugin(),
        new Webpack.optimize.UglifyJsPlugin({
          compressor: {
            warnings: false
          }
        }),
        ExtractSASS
      );
  
      webpackConfig.module.loaders.push({
        test: /\.scss$/i,
        loader: ExtractSASS.extract(['css', 'sass'])
      });
  
    } else {
      webpackConfig.plugins.push(
        new Webpack.HotModuleReplacementPlugin()
      );
  
      webpackConfig.module.loaders.push({
        test: /\.scss$/i,
        loaders: ['style', 'css', 'sass']
      }, {
        test: /\.js$/,
        loader: 'eslint',
        exclude: /node_modules/
      });
  
      webpackConfig.devServer = {
        contentBase: './dist',
        hot: true,
        port: options.port,
        inline: true,
        progress: true
      };
    }
  
    return webpackConfig;
  
  }
  