const webpack = require("webpack");
const path = require("path");
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const root = path.join(__dirname, "/app");


module.exports = {
	context: root,
  	devtool: "eval", //'cheap-module-eval-source-map',
  	watch: true,
  	stats: false, // Don't show stats in the console
  	name: "app",
	resolve: {
		unsafeCache: true,
		alias: {
			"assets": path.join(__dirname, "/assets"),
			"styles": path.join(__dirname, "../styles"),
			"components": path.join(__dirname, "/app/components"),
			"containers": path.join(__dirname, "/app/containers"),
			"lib": path.join(__dirname, "/app/lib"),
			"translations": path.join(__dirname, "/app/translations"),
			"utils": path.join(__dirname, "/app/utils"),
            "constants": path.join(__dirname, "/app/constants")
		},
		extensions: ['.js', '.jsx', '.json', '.scss', '.css']
	},
	entry: {
		"app": [
			"babel-polyfill", 
    		"eventsource-polyfill",
    		"webpack-hot-middleware/client?name=app&reload=true",
			//path.join(__dirname, "/src/browser/index.js")
			path.join(__dirname, "/app/index.js")
		]
	},
	output: {
        path: path.join(__dirname, "../backend/resources/resources"),
		filename: "[name].js",
		publicPath: '/resources',
		hotUpdateChunkFilename: 'hot/[id].[hash].hot-update.js',
		hotUpdateMainFilename: 'hot/[hash].hot-update.json'
	},
	module: {
		rules: [ 
			{
				test: /\.js$/, 
				include: root, 
                exclude: /node_modules/,
				use: ["babel-loader"]
			},
            {
                test: /\.css$/,
                exclude: /node_modules/,
                use: ['css-hot-loader'].concat(ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'postcss-loader']
                }))
                
            },
            {
                test: /\.scss$/,
                exclude: /node_modules/,
                use: ['css-hot-loader'].concat(ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'sass-loader']
                }))
            },			
			{
				test: /\.(png|jpg)$/, 
				use: {
					loader: "url-loader",
					options: {
						limit: 8192
					}
				}
			},
			{
    			test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
				use: [{
					loader: 'file-loader',
					options: {
						name: '[name].[ext]',
						outputPath: 'fonts'
					}
				}]    			
  			}			
		]
	},
	plugins: [ 
		new webpack.HotModuleReplacementPlugin(),
		new ExtractTextPlugin("[name].css")
	]
};

