const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const tsConfigFile = './tsconfig.json';

module.exports = [
	{
		entry: './index.tsx',
		mode: 'development',
		module: {
			rules: [
				{
					test: /\.tsx?$/,
					use: [
						{
							loader: 'ts-loader',
							options: {
								transpileOnly: true,
								experimentalWatchApi: true
							}
						}
					]
				},
				{
					test: /\.scss$/,
					use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'sass-loader' }],
					exclude: /node_modules/
				},
				{
					test: /fonts(.*?)\.(eot|svg|ttf|woff|woff2)$/,
					use: [
						{
							loader: 'file-loader',
							options: {
								name: '/fonts/[name].[ext]'
							}
						}
					]
				}
			]
		},
		resolve: {
			extensions: ['.tsx', '.ts', '.js', '.json']
		},

		plugins: [
			new HtmlWebpackPlugin({
				template: './pages/index.html',
				title: 'BotsBotsBots'
			}),
			new webpack.DefinePlugin({
				'process.env.NODE_ENV': JSON.stringify('development'), // use 'development' unless process.env.NODE_ENV is defined
				'process.env.DEBUG': JSON.stringify(false),
				'process.env.AWS_REGION': JSON.stringify('us-west-2'),
				'process.env.APP_API': JSON.stringify(process.env.APP_API),
				'process.env.APP_ENV': JSON.stringify(process.env.APP_ENV || 'testing'),
				'process.env.SLACK_CLIENT_ID': JSON.stringify(process.env.SLACK_CLIENT_ID)
			}),
			new CopyWebpackPlugin([
				{
					from: '**/*',
					context: './public/',
					to: '.'
				}
			])
		],
		target: 'web',
		node: {
			process: 'mock',
			Buffer: true,
			fs: 'empty'
		},
		devServer: {
			contentBase: path.join(__dirname, 'public'),
			index: 'index.html'
		},
		output: {
			filename: 'js/index.[hash].js',
			path: path.resolve(__dirname, 'public'),
			libraryTarget: 'umd',
			publicPath: '/'
		}
	}
];
