Repository: toss/es-toolkit
File: rollup.config.mjs (JavaScript)

Code before:
    input: inputFile,
    plugins: [
      tsPlugin({
        exclude: [...testPatterns],
        compilerOptions: {
          sourceMap: sourcemap,
          inlineSources: sourcemap || undefined,
          removeComments: true,
          declaration: false,
        },
      }),
    ],
    output: {
      plugins: [
        // Minify with terser, but with a configuration that optimizes for
        // readability in browser DevTools (after re-indenting by DevTools).
        terserPlugin({
          // Terser defaults to ES5 for syntax it adds or rewrites
          ecma: 2018,
          // Readable function names (not just in final export)
          keep_fnames: true,
          // Turn off compress.sequences to keep the assignments to the toolkit
          // object readable, instead of turning them into a huge list of
          // comma-separated expressions.
          compress: { sequences: false },
        }),
      ],
      format: 'iife',
      name,
      file: outFile,
      sourcemap,
      generatedCode: 'es2015',
    },
  };
}

/**
 * @type {(options: {entrypoints: string[]; outDir: string}) => import('rollup').RollupOptions}
 */
function declarationOptions({ entrypoints, outDir }) {
  return {
    plugins: [dtsPlugin()],
    input: mapInputs(entrypoints),
    output: [
      {
        format: 'esm',
        dir: outDir,
        generatedCode: 'es2015',
        ...fileNames('d.mts'),
        preserveModules: true,
        preserveModulesRoot: 'src',

Review comment (suggestion):
A few changes to the Terser defaults to produce a more readable `dist/browser.global.js` file (once beautified):

- Keep function names. When this is off, the properties added to the `_` object are using the expected names, but most of them call to functions declared earlier in the bundle, and those function names are mangled (with code looking like `t.difference = function (...args) { return x$(...args) }`), resulting in JS errors being logged as an error in the `x$` function, which is not ideal.
- The `compress.sequences` feature of Terser leads to a particularly arcane output looking like:

```js
// line 300
return (
  t.fn1 = /* ... */,
  t.fn2 = /* ... */,
  /* ... */

// line 800
  t.fn93 = /* ... */,
  t
)
```

which is really hard to follow, and not actually smaller than the output with this option turned off:

```js
// line 300
t.fn1 = /* ... */;
t.fn2 = /* ... */;
/* ... */
// line 800
t.fn93 = /* ... */;
return t;
```

Code after:
    input: inputFile,
    plugins: [
      tsPlugin({
        exclude: [...testPatterns],
        compilerOptions: {
          sourceMap: sourcemap,
          inlineSources: sourcemap || undefined,
          removeComments: true,
          declaration: false,
        },
      }),
    ],
    output: {
      plugins: [
        // Minify with terser, but with a configuration that optimizes for
        // readability in browser DevTools (after re-indenting by DevTools).
        terserPlugin({
          // Terser defaults to ES5 for syntax it adds or rewrites
          ecma: 2020,
          // Readable function names (not just in final export)
          keep_fnames: true,
          // Turn off compress.sequences to keep the assignments to the toolkit
          // object readable, instead of turning them into a huge list of
          // comma-separated expressions.
          compress: { sequences: false },
        }),
      ],
      format: 'iife',
      name,
      file: outFile,
      sourcemap,
      generatedCode: 'es2015',
    },
  };
}

/**
 * @type {(options: {entrypoints: string[]; outDir: string}) => import('rollup').RollupOptions}
 */
function declarationOptions({ entrypoints, outDir }) {
  return {
    plugins: [dtsPlugin()],
    input: mapInputs(entrypoints),
    output: [
      {
        format: 'esm',
        dir: outDir,
        generatedCode: 'es2015',
        ...fileNames('d.mts'),
        preserveModules: true,
        preserveModulesRoot: 'src',