const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );

module.exports = {
	...defaultConfig,
	resolve: {
		...( defaultConfig.resolve || {} ),
		extensions: [
			'.ts',
			'.tsx',
			'.js',
			'.jsx',
			'.json',
		],
	},
	module: {
		...( defaultConfig.module || {} ),
		rules: [
			...( defaultConfig.module?.rules || [] ),
			{
				test: /\.tsx?$/,
				exclude: /node_modules/,
				use: {
					loader: require.resolve( 'babel-loader' ),
					options: {
						cacheDirectory: true,
						presets: [
							require.resolve( '@wordpress/babel-preset-default' ),
							require.resolve( '@babel/preset-typescript' ),
						],
					},
				},
			},
		],
	},
	entry: {
		...( typeof defaultConfig.entry === 'function'
			? defaultConfig.entry()
			: defaultConfig.entry ),
		'currency-converter-frontend': path.resolve(
			process.cwd(),
			'src',
			'currency-converter-frontend.ts'
		),
	},
};
