const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');

module.exports = {
  entry: [
    'babel-polyfill',
    './src/scripts/app.js',
    './src/less/styles.less'
  ],

  resolve: {
    extensions: ['.js', '.jsx', '.less']
  },

  output: {
    path: path.join(__dirname, '/public/assets'),
    filename: 'app.js',
    publicPath: `/assets/`
  },

  module: {
    rules: [
      // Fix grapheme-breaker
      {
        enforce: 'post',
        test: /\.js$/,
        include: /node_modules\/grapheme-breaker/,
        loader: 'transform/cacheable?brfs'
      },
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          cacheDirectory: true,
          presets: [
            ['es2015', { "modules": false }],
            'react',
            'stage-1'
          ]
        }
      },
      { test: /\.json$/, loader: 'json' },
      { test: /\.css$/, loader: ExtractTextPlugin.extract({ fallbackLoader: 'style', loader: 'css!postcss' }) },
      { test: /\.less$/, loader: ExtractTextPlugin.extract({ fallbackLoader: 'style', loader: 'css!postcss!less' }) },
      { test: /\.(ttf|eot|woff(2)?)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url?limit=15000' },
      { test: /\.(png|jpg|svg)$/, loader: 'file?name=[hash].[ext]' }
    ]
  },

  plugins: [
    // An appropriate alternative to envify.
    new webpack.EnvironmentPlugin([
      'API_HOST', 'NODE_ENV', 'MAPBOX_ACCESS_TOKEN', 'GOOGLE_ANALYTICS_ID'
    ]),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin(),
    new webpack.optimize.DedupePlugin(),
    new ExtractTextPlugin({
      filename: 'styles.css',
      allChunks: true
    }),
    new webpack.LoaderOptionsPlugin({
      options: {
        context: __dirname,
        postcss: [
          autoprefixer
        ]
      }
    })
  ]
};

@@ -654,16 +654,23 @@
 ransform
+-loader
 /cacheab
@@ -678,16 +678,16 @@
 e?brfs'%0A
-
       %7D,
@@ -775,16 +775,23 @@
 : 'babel
+-loader
 ',%0A     
@@ -1013,16 +1013,23 @@
 r: 'json
+-loader
 ' %7D,%0A   
@@ -1099,32 +1099,39 @@
 ckLoader: 'style
+-loader
 ', loader: 'css!
@@ -1129,24 +1129,31 @@
 er: 'css
+-loader
 !postcss
 ' %7D) %7D,%0A
@@ -1144,16 +1144,23 @@
 !postcss
+-loader
 ' %7D) %7D,%0A
@@ -1242,16 +1242,23 @@
 : 'style
+-loader
 ', loade
@@ -1264,24 +1264,31 @@
 er: 'css
+-loader
 !postcss
 !less' %7D
@@ -1283,13 +1283,27 @@
 tcss
-!less
+-loader!less-loader
 ' %7D)
@@ -1383,16 +1383,23 @@
 er: 'url
+-loader
 ?limit=1
@@ -1454,16 +1454,23 @@
 r: 'file
+-loader
 ?name=%5Bh
@@ -1714,32 +1714,32 @@
 eOrderPlugin(),%0A
+
     new webpack.
@@ -1769,49 +1769,8 @@
 (),%0A
-    new webpack.optimize.DedupePlugin(),%0A
     

Fix webpack config for production