-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.mjs
90 lines (84 loc) · 1.9 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Inspired by
// https://github.com/jaredpalmer/tsdx/blob/2d7981b/src/createRollupConfig.ts
// Import rollup plugins
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import path from 'path';
const outputOptions = {
all: {
inlineDynamicImports: true,
sourcemap: true,
globals: { react: 'React' },
},
esm: {
format: 'esm',
freeze: false,
esModule: true,
exports: 'named',
},
cjs: {
format: 'cjs',
},
min: {
plugins: [
terser({
output: { comments: false },
compress: {
keep_infinity: true,
pure_getters: true,
passes: 10,
},
ecma: 2020,
toplevel: true,
warnings: true,
}),
],
},
};
const config = {
plugins: [
// Resolve bare module specifiers to relative paths
resolve(),
// All bundled external modules need to be converted from CJS to ESM
commonjs(),
typescript({
declarationDir: 'dist',
compilerOptions: {
sourceMap: true,
declaration: true,
jsx: 'react',
},
}),
],
input: './src/index.tsx',
output: [
{
file: './dist/react-image-display-control.mjs',
...outputOptions.all,
...outputOptions.esm,
},
{
file: './dist/react-image-display-control.min.mjs',
...outputOptions.all,
...outputOptions.esm,
...outputOptions.min,
},
{
file: './dist/react-image-display-control.cjs',
...outputOptions.all,
...outputOptions.cjs,
},
{
file: './dist/react-image-display-control.min.cjs',
...outputOptions.all,
...outputOptions.cjs,
...outputOptions.min,
},
],
external: (id) => {
return !id.startsWith('.') && !path.isAbsolute(id);
},
};
export default config;