|
| 1 | +/* eslint-disable import/no-default-export */ |
| 2 | +/* eslint-disable no-unused-vars */ |
| 3 | + |
1 | 4 | import { defineConfig } from 'rollup'
|
2 | 5 | import bundleSize from 'rollup-plugin-bundle-size'
|
3 | 6 | import dts from 'rollup-plugin-dts'
|
4 | 7 | import esbuild from 'rollup-plugin-esbuild'
|
5 | 8 | import { terser } from 'rollup-plugin-terser'
|
| 9 | +import pkg from './package.json' |
| 10 | + |
| 11 | +const MINIFY = true |
6 | 12 |
|
7 | 13 | const src = (file) => `src/${file}`
|
8 | 14 | const dist = (file) => `dist/${file}`
|
9 | 15 |
|
10 |
| -const bundle = (input, config) => |
| 16 | +const bundle = (input, { plugins = [], ...config }) => |
11 | 17 | defineConfig({
|
12 | 18 | ...config,
|
13 | 19 | input,
|
| 20 | + plugins: plugins.filter(Boolean).concat(bundleSize()), |
| 21 | + |
| 22 | + // do not bundle packages |
14 | 23 | external: (id) => !/^[./]/.test(id),
|
15 |
| - plugins: [...(config.plugins || []), bundleSize()], |
16 | 24 | })
|
17 | 25 |
|
18 | 26 | const config = defineConfig([
|
| 27 | + /* Compiled JS (CommonJS, ESM) */ |
19 | 28 | bundle(src('index.ts'), {
|
20 |
| - plugins: [esbuild(), terser()], |
| 29 | + plugins: [esbuild(), MINIFY && terser()], |
21 | 30 | output: [
|
22 | 31 | {
|
23 |
| - file: dist('index.js'), |
| 32 | + file: pkg.main, |
24 | 33 | format: 'cjs',
|
25 | 34 | },
|
26 | 35 | {
|
27 |
| - file: dist('index.mjs'), |
| 36 | + file: pkg.module, |
28 | 37 | format: 'es',
|
29 | 38 | },
|
30 | 39 | ],
|
31 | 40 | }),
|
| 41 | + |
| 42 | + /* TS declarations */ |
32 | 43 | bundle(src('index.ts'), {
|
33 | 44 | plugins: [dts()],
|
34 | 45 | output: [
|
35 | 46 | {
|
36 |
| - file: dist('index.d.ts'), |
| 47 | + file: pkg.types, |
37 | 48 | format: 'es',
|
38 | 49 | },
|
39 | 50 | ],
|
|
0 commit comments