forked from ReactTooltip/react-tooltip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.prod.js
106 lines (96 loc) · 2.47 KB
/
rollup.config.prod.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import commonjs from '@rollup/plugin-commonjs'
import filesize from 'rollup-plugin-filesize'
import postcss from 'rollup-plugin-postcss'
import progress from 'rollup-plugin-progress'
import replace from '@rollup/plugin-replace'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import ts from '@rollup/plugin-typescript'
import { terser } from 'rollup-plugin-terser'
import typescript from 'typescript'
import * as pkg from './package.json'
const input = ['src/index.tsx']
const name = 'ReactTooltip'
const external = [
...Object.keys(pkg.peerDependencies ?? {}),
...Object.keys(pkg.dependencies ?? {}),
]
const buildFormats = [
{
file: 'dist/react-tooltip.umd.js',
format: 'umd',
globals: {
'@floating-ui/dom': 'FloatingUIDOM',
react: 'React',
'react-dom': 'ReactDOM',
classnames: 'classNames',
'prop-types': 'PropTypes',
},
},
{
file: 'dist/react-tooltip.cjs',
format: 'cjs',
},
{
file: 'dist/react-tooltip.mjs',
format: 'es',
},
]
const sharedPlugins = [
progress(),
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify('development'),
},
}),
nodeResolve(),
ts({
typescript,
tsconfig: './tsconfig.json',
noEmitOnError: false,
// declaration: true,
// declarationDir: './build',
}),
commonjs({
include: 'node_modules/**',
}),
]
// this step is just to build the minified javascript files
const minifiedBuildFormats = buildFormats.map(({ file, ...rest }) => ({
file: file.replace(/(\.[cm]?js)$/, '.min$1'),
...rest,
minify: true,
plugins: [terser(), filesize()],
}))
const allBuildFormats = [...buildFormats, ...minifiedBuildFormats]
const config = allBuildFormats.map(
({ file, format, globals, plugins: specificPlugins, minify }) => {
const plugins = [
...sharedPlugins,
postcss({
extract: minify ? 'react-tooltip.min.css' : 'react-tooltip.css', // this will generate a specific file and override on multiples build, but the css will be the same
autoModules: true,
include: '**/*.css',
extensions: ['.css'],
plugins: [],
minimize: Boolean(minify),
}),
]
if (specificPlugins && specificPlugins.length) {
plugins.push(...specificPlugins)
}
return {
input,
output: {
file,
format,
name,
globals,
sourcemap: true,
},
external,
plugins,
}
},
)
export default config