const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const config = require('../config');

const paths = config.utils_paths;

const vendors = [
  'fastclick',
  'promise',
  'react-redux',
  'redux',
  'redux-thunk',
  'superagent',
  'react',
  'react-dom',
  'react-router-dom',
  'history',
];

module.exports = {
  output: {
    filename: '[name]_[hash].js',
    path: paths.lib(),
    library: '[name]_[hash]',
  },
  resolve: {
    extensions: ['.web.tsx', '.web.ts', '.web.jsx', '.web.js', '.ts', '.tsx', '.js', '.jsx', '.json'],
  },
  entry: {
    lib: vendors,
  },
  plugins: [
    new webpack.DefinePlugin(config.globals),
    new CleanWebpackPlugin(['*'], {
      root: paths.lib(),
    }),
    new webpack.ProgressPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false,
      },
    }),
    new webpack.DllPlugin({
      path: paths.lib('manifest.json'),
      name: '[name]_[hash]',
      context: paths.lib(),
    }),
  ],
};
