const { babel } = require("@rollup/plugin-babel");
const replace = require("@rollup/plugin-replace");
const terser = require("@rollup/plugin-terser");

const banner = require("../banner");
const version = require("../package.json").version;

const babelOptions = {
	babelHelpers: "bundled",
	babelrc: false,
	exclude: "node_modules/**",
	presets: [
		[
			"@babel/preset-env",
			{
				loose: true,
				modules: false,
			},
		],
	],
	plugins: [
		["@babel/plugin-proposal-class-properties", { loose: true }],
		"@babel/plugin-transform-object-assign",
	],
};

const replaceVersion = replace({
	delimiters: ["", ""],
	preventAssignment: true,
	values: {
		"#__VERSION__#": version,
	},
});

module.exports = [
	{
		input: "src/index.js",
		plugins: [babel(babelOptions), replaceVersion],
		output: {
			banner,
			format: "es",
			freeze: false,
			exports: "named",
			interop: false,
			sourcemap: true,
			file: "./dist/hammer.esm.js",
		},
	},
	{
		input: "src/hammer.js",
		plugins: [babel(babelOptions), replaceVersion],
		output: {
			banner,
			format: "umd",
			name: "Hammer",
			exports: "default",
			freeze: false,
			interop: false,
			sourcemap: true,
			file: "./dist/hammer.js",
		},
	},
	{
		input: "src/hammer.js",
		plugins: [
			babel(babelOptions),
			replaceVersion,
			terser({
				format: {
					comments: /Naver/,
				},
			}),
		],
		output: {
			banner,
			format: "umd",
			name: "Hammer",
			exports: "default",
			freeze: false,
			interop: false,
			sourcemap: true,
			file: "./dist/hammer.min.js",
		},
	},
];
