const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
const postcssImport = require('postcss-import');

//Standard Node environment variables for determining if we are in PRODUCTION
//To enable / disable the hot module replacement.
const PRODUCTION = process.env.NODE_ENV === 'production';
const env = process.env.NODE_ENV || 'development';
const PORT = process.env.PORT || 8080;
const HOST = process.env.HOST || 'localhost'; // Set to 0.0.0.0 on cloud9 if needed
const URL = `http://${HOST}:${PORT}`

const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
  app: path.join(__dirname, 'app'),
  build: path.join(__dirname, 'build'),
  public: path.join(__dirname, 'public'),
  images: path.join(__dirname, 'assets/images'),
  style: path.join(__dirname, 'app/stylesheets')
};

module.exports = {
  devtool: 'source-map',
  entry: [
    PATHS.app
  ],
  output: {
    path: PATHS.build,
    publicPath: '/',
    filename: 'bundle.js'
  },
  plugins: [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.UglifyJsPlugin({
      minimize: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.DefinePlugin({
      'process.env': {
        'NODE_ENV': JSON.stringify('production')
      }
    })
  ],
  module: {
    loaders: [
        // Set up jsx. This accepts js too thanks to RegExp
      {
        test: /\.jsx?$/,
        // Enable caching for improved performance during development
        // It uses default OS directory by default. If you need something
        // more custom, pass a path to it. I.e., babel?cacheDirectory=<path>
        loaders: ['babel?cacheDirectory'],
        // Parse only app files! Without this it will go through entire project.
        // In addition to being slow, that will most likely result in an error.
        include: PATHS.app
      },
      {
        // Test expects a RegExp! Note the slashes!
        test: /\.css$/,
        loader: "style-loader!css-loader!postcss-loader",
        // Include accepts either a path or an array of paths.
        include: PATHS.style
      },
      {
        test: /\.(png|jpg)$/,
        loader: 'file-loader?name=images/[name].[ext]',
        path: PATHS.images
      }
    ]
  },
  postcss: function (webpack) {
    return [
      postcssImport({ addDependencyTo: webpack }),
      require('autoprefixer'),
      require('precss'),
      require('cssnano')
    ];
  }
};

@@ -25,816 +25,43 @@
 th')
-;%0Aconst merge = require('webpack-merge');%0Aconst webpack = require('webpack');%0Aconst postcssImport = require('postcss-import');%0A%0A//Standard Node environment variables for determining if we are in PRODUCTION%0A//To enable / disable the hot module replacement.%0Aconst PRODUCTION = process.env.NODE_ENV === 'production';%0Aconst env = process.env.NODE_ENV %7C%7C 'development';%0Aconst PORT = process.env.PORT %7C%7C 8080;%0Aconst HOST = process.env.HOST %7C%7C 'localhost'; // Set to 0.0.0.0 on cloud9 if needed%0Aconst URL = %60http://$%7BHOST%7D:$%7BPORT%7D%60%0A%0Aconst TARGET = process.env.npm_lifecycle_event;%0Aconst PATHS = %7B%0A  app: path.join(__dirname, 'app'),%0A  build: path.join(__dirname, 'build'),%0A  public: path.join(__dirname, 'public'),%0A  images: path.join(__dirname, 'assets/images'),%0A  style: path.join(__dirname, 'app/stylesheets')%0A%7D;
+%0Aconst webpack = require('webpack')
 %0A%0Amo
@@ -102,16 +102,17 @@
 e-map',%0A
+%0A
   entry:
@@ -122,23 +122,28 @@
     
-PATHS.app
+'./src/index'
 %0A  %5D,%0A
+%0A
   ou
@@ -164,73 +164,98 @@
 th: 
-PATHS.build,%0A    publicPath: '/',%0A    filename: 'bundle.js
+path.join(__dirname, 'build'),%0A    filename: 'bundle.js',%0A    publicPath: '/build/
 '%0A  %7D,%0A
+%0A
   pl
@@ -549,16 +549,17 @@
 %7D)%0A  %5D,%0A
+%0A
   module
@@ -587,77 +587,9 @@
     
-  // Set up jsx. This accepts js too thanks to RegExp%0A      %7B%0A       
+%7B
  tes
@@ -596,17 +596,16 @@
 t: /%5C.js
-x
 ?$/,%0A   
@@ -613,528 +613,67 @@
     
-// Enable caching for improved performance during development%0A        // It uses default OS directory by default. If you need something%0A        // more custom, pass a path to it. I.e., babel?cacheDirectory=%3Cpath%3E%0A        loaders
+loader
 : 
-%5B
 'babel
-?cacheDirectory'%5D,%0A        // Parse only app files! Without this it will go through entire project.%0A        // In addition to being slow, that will most likely result in an error.%0A        include: PATHS.app%0A      %7D,%0A      %7B%0A        // Test expects a RegExp! Note the slashes!%0A       
+',%0A        exclude: /node_modules/ %7D,%0A      %7B
  tes
@@ -678,19 +678,21 @@
 est: /%5C.
+s
 css
+?
 $/,%0A    
@@ -707,48 +707,24 @@
 er: 
-%22
+'
 style
--loader!css-loader!postcss-loader%22
+!css!sass'
 ,%0A  
@@ -733,97 +733,54 @@
     
-// I
+i
 nclude
- accepts either a path or an array of paths.%0A        include: PATHS.style%0A     
+: path.join(__dirname, 'src', 'styles')
  %7D,%0A
@@ -786,24 +786,16 @@
 %0A      %7B
-%0A       
  test: /
@@ -800,17 +800,11 @@
  /%5C.
-(
 png
-%7Cjpg)
 $/,%0A
@@ -828,276 +828,102 @@
 file
--loader?name=images/%5Bname%5D.%5Bext%5D',%0A        path: PATHS.images%0A      %7D%0A    %5D%0A  %7D,%0A  postcss: function (webpack) %7B%0A    return %5B%0A      postcssImport(%7B addDependencyTo: webpack %7D),%0A      require('autoprefixer'),%0A      require('precss'),%0A      require('cssnano')
+' %7D,%0A      %7B test: /%5C.(ttf%7Ceot%7Csvg%7Cwoff(2)?)(%5C?%5Ba-z0-9%5D+)?$/,%0A        loader: 'file'%7D
 %0A    %5D
-;
 %0A  %7D%0A%7D
-;
 %0A

add build scripts for production