const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');

const minify = process.env.MINIFY ? '.min' : '';
let plugins = [new ExtractTextPlugin(`${__dirname}/lib/[name].css`)];
if (minify) {
  plugins.push(new UglifyJsPlugin({ minimize: true }));
}

const config = {
  entry: {
    [`kd-ui${minify}`]: [`${__dirname}/app/index-cdn.js`]
  },
  devtool: 'source-map',
  output: {
    filename: `${__dirname}/lib/[name].js`,
    libraryTarget: 'umd',
    library: 'KdUi'
  },
  externals:{
    "react": "React",
    "react-dom": "ReactDOM"
  },
  module: {
    loaders: [
      {
        test: /(\.jsx|\.js)$/,
        loader: 'babel-loader',
        exclude: /(node_modules|bower_components)/
      },
      {
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract('style', 'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!sass?indentedSyntax=true&sourceMap=true')
      },
      {
        test: /\.(png|gif)(\?.*)?$/,
        loader: 'url-loader?mimetype=image/png'
      },
    ]
  },
  resolve: {
    root: path.resolve('./app'),
    extensions: ['', '.js']
  },
  plugins: plugins,
  postcss: {}
};

module.exports = config;
