'use strict';
const config = require('../config');
const webpack = require('webpack');
const merge = require('webpack-merge');
const baseWebpackConfig = require('./webpack.base.conf');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const cssSourceMap = config.dev.cssSourceMap;

baseWebpackConfig.entry.main=[
    'react-hot-loader/patch',
    'webpack-hot-middleware/client?noInfo=true&reload=true',
    './src/main.js'
];

module.exports = merge(baseWebpackConfig, {
    devtool: '#cheap-module-eval-source-map',
    resolve: {
        alias: {
          'react': 'anujs/dist/ReactIE',
          'react-server': 'anujs/dist/ReactDOMServer',
          'react-dom': 'anujs/dist/ReactIE',
          'prop-types': 'anujs/lib/ReactPropTypes'
        }
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            minimize: false,
                            sourceMap: cssSourceMap,
                            localIdentName: '[path][hash:base64:5]',
                            module: true
                        }
                    }
                ]
            },
            {
                test: /\.less/,
                use: [
                    'style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            minimize: false,
                            sourceMap: cssSourceMap,
                            importLoaders: 1,
                            localIdentName: '[path][hash:base64:5]',
                            module: true
                        }
                    },
                    {
                        loader: 'less-loader',
                        options: {
                            sourceMap: cssSourceMap
                        }
                    }]

            }
        ]
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': config.dev.env
        }),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: 'index.html',
            inject: 'body'
        }),
        new FriendlyErrorsPlugin()
    ]
});