/**
 * Warning: duplicate of webpack.conf.js in project root.
 * The one in project root is needed to run the webpack-dev-server
 *
 * @type {webpack|exports|module.exports}
 */
var webpack = require('webpack');
var path = require('path');
var root = path.resolve('.');

module.exports = {
  build: {
    entry: {
      app: ['webpack/hot/dev-server', root + '/app/scripts/app.js'],
      vendor: ['jquery', 'underscore', 'backbone']
    },
    output: {
      path: root + '/dist',
      filename: 'bundle.app.js'
    },
    module: {
      // be sure to npm install --save-dev each loader
      loaders: [
        {test: /\.ejs/, loader: 'ejs-loader'},
        {test: /\.hbs/, loader: 'handlebars-loader'},
        {test: /\.json$/, loader: 'json-loader'},
        {test: /\.jpe?g$|\.eot$|\.gif$|\.png$|\.svg$|\.woff$|\.woff2$|\.ttf$/, loader: "file" },
        {test: /\.scss$/, loader: 'style-loader!css-loader!sass-loader!autoprefixer-loader'}
      ]
    },
    plugins: [
      new webpack.ResolverPlugin(
        new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
      ),
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery"
      }),
      new webpack.ProvidePlugin({
        _: "underscore"
      }),
      new webpack.ProvidePlugin({
        Bloodhound: "Bloodhound"
      }),
      new webpack.optimize.CommonsChunkPlugin(
        'vendor',
        'bundle.vendor.js'
      ),
      new webpack.HotModuleReplacementPlugin()
    ],
    devServer: {
      contentBase: root + '/dist',
      noInfo: true,
      hot: true,
      inline: true
    }
  }
};
