/**
 * This file ensures we can write JS that has a dependancy on the 'PersonalizeWP' frontend JS
 */
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const DependencyExtractionWebpackPlugin = require('@wordpress/dependency-extraction-webpack-plugin');

module.exports = {
	...defaultConfig,
	plugins: [
		...defaultConfig.plugins.filter(
			plugin => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
		),
		new DependencyExtractionWebpackPlugin({
			requestToExternal(request) {
				if (request === 'PersonalizeWP') return 'PersonalizeWP';
			},
			requestToHandle(request) {
				if (request === 'PersonalizeWP') return 'personalizewp';
			}
		})
	]
};
