const BabiliPlugin = require('babili-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlPluign = require('html-webpack-plugin');
const path = require('path');
const EnvironmentPlugin = require('webpack/lib/EnvironmentPlugin');
const OccurrenceOrderPlugin = require('webpack/lib/optimize/OccurrenceOrderPlugin');
const pkg = require('./package.json');

process.env.NODE_ENV = process.env.NODE_ENV || 'development';

module.exports = {
  devServer: {
    host: '0.0.0.0',
    port: +(process.env.PORT || 8080),
  },
  devtool: 'source-map',
  entry: path.join(__dirname, 'src', 'client.jsx'),
  module: {
    loaders: [
      {
        exclude: /node_modules/,
        loader: 'babel-loader',
        test: /\.jsx?$/,
      },
      {
        loaders: [
          'isomorphic-style-loader',
          'css-loader',
        ],
        test: /\.css$/,
      },
      {
        loader: 'handlebars-loader',
        test: /\.hbs$/,
      },
    ],
  },
  output: {
    filename: process.env.NODE_ENV === 'development' ? '[name].js?[chunkhash]' : '[name].[chunkhash].js',
    path: path.join(__dirname, 'build', 'public'),
    publicPath: '/',
  },
  plugins: [
    new HtmlPluign({
      minify: {
        collapseBooleanAttributes: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true,
        removeOptionalTags: true,
        removeScriptTypeAttributes: true,
        removeStyleLinkTypeAttributes: true,
      },
      template: path.join(__dirname, 'src', 'templates', 'index.hbs'),
      title: process.env.BABERU_TV_SITE_NAME || `${pkg.name} (v${pkg.version})`,
    }),
    new EnvironmentPlugin([
      'NODE_ENV',
    ]),
    new CopyPlugin([
      {
        from: path.join(__dirname, 'src', 'assets', 'favicon.ico'),
        to: path.join(__dirname, 'build', 'public', 'favicon.ico'),
      },
      {
        from: path.join(__dirname, 'src', 'assets', '404.html'),
        to: path.join(__dirname, 'build', 'public', '404.html'),
      },
    ]),
    ...(process.env.NODE_ENV !== 'development' ? [
      new OccurrenceOrderPlugin(),
      new BabiliPlugin(),
    ] : []),
  ],
  resolve: {
    extensions: [
      '.js',
      '.jsx',
    ],
  },
};

@@ -624,30 +624,28 @@
 dule: %7B%0A    
-loader
+rule
 s: %5B%0A      %7B
@@ -686,22 +686,44 @@
         
-loader
+test: /%5C.jsx?$/,%0A        use
 : 'babel
@@ -742,33 +742,17 @@
     
-  test: /%5C.jsx?$/
+%7D
 ,%0A      
 %7D,%0A 
@@ -743,34 +743,49 @@
    %7D,%0A      
-%7D,
+%7B
 %0A      
-%7B
+  test: /%5C.css$/,
 %0A        loa
@@ -785,15 +785,11 @@
     
-loaders
+use
 : %5B%0A
@@ -870,102 +870,75 @@
     
-  test: /%5C.css$/,%0A      %7D,%0A      %7B%0A        loader: 'handlebars-loader',%0A        test: /%5C.hbs$/
+%7D,%0A      %7B%0A        test: /%5C.hbs$/,%0A        use: 'handlebars-loader'
 ,%0A  

Change webpack config for loaders Close #171 (#173)