/** @format */

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
var PACKAGE = require('./package.json');
const chalk = require('chalk');
//env.production

module.exports = (env) => {
	console.log(chalk.white.bgYellow.bold('TYPE: ', env?.production ? 'production' : 'development'));
	console.log(chalk.white.bgYellow.bold('PACKAGE_VERSION: ', PACKAGE.version))
	return {
		entry: path.join(__dirname, 'src', 'index.js'),
		mode: 'development',
		output: {
			path: env?.production
				? path.resolve(__dirname, 'prod', `${PACKAGE.version}`)
				: path.resolve(__dirname, 'dist'),
		},
		// devServer: {
		// 	port: 80,
		// },
		module: {
			rules: [
				{
					test: /\.(jsx|js)$/,
					use: {
						loader: 'babel-loader',
						options: {
							presets: [['@babel/env', { loose: true }], '@babel/preset-react'],
						},
					},
				},
				{
					test: /\.css$/i,
					use: ['style-loader', 'css-loader', 'postcss-loader'],
				},
				{
					test: /\.(png|jp(e*)g|svg|gif)$/,
					use: ['file-loader'],
				},
				{
					test: /\.svg$/,
					use: ['@svgr/webpack'],
				},
				{
					test: /\.(mp3|wav)$/i,
					loader: 'file-loader',
				},
			],
		},
		resolve: {
			extensions: ['.js', '.jsx', '.json'],
		},
		plugins: [
			new HtmlWebpackPlugin({
				template: path.join(__dirname, 'src', 'index.html'),
			}),
		],
	};
};
