const path = require('path');
const env = process.env.WEBPACK_ENV;

// Simply configure those 4 variables:
const JS_SOURCE_FILES = ['core-js', './formatPanelConfig/config.js'];
const OUTPUT_FILENAME = 'config';
const DEST_FOLDER = 'dist';

const OUTPUT_FILE = `${OUTPUT_FILENAME}.js`;

const { devtool, mode } =
	env == 'build'
		? {
				devtool: false,
				mode: 'production'
		  }
		: {
				devtool: 'source-map',
				mode: 'development'
		  };

module.exports = {
	mode,
	entry: JS_SOURCE_FILES,
	output: {
		path: path.join(__dirname, DEST_FOLDER),
		filename: OUTPUT_FILE,
		libraryTarget: 'umd',
		umdNamedDefine: true,
		clean: true
	},
	module: {
		rules: [
			{
				test: /\.m?js$/,
				exclude: /(node_modules)/,
				use: {
					loader: 'babel-loader',
					options: {
						presets: ['@babel/preset-env']
					}
				}
			}
		]
	},
	devtool
};
