-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
rollup.config.prod.js
126 lines (115 loc) · 3.2 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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 replaceBeforeSaveFile from './rollup-plugins/replace-before-save-file.js'
import * as pkg from './package.json'
const input = ['src/index.tsx']
const name = 'ReactTooltip'
const banner = `
/*
* React Tooltip
* {@link https://github.com/ReactTooltip/react-tooltip}
* @copyright ReactTooltip Team
* @license MIT
*/`
const external = [
...Object.keys(pkg.peerDependencies ?? {}),
...Object.keys(pkg.dependencies ?? {}),
]
const buildFormats = [
{
file: 'dist/react-tooltip.mjs',
format: 'es',
},
{
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,
}),
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({ compress: { directives: false } }), 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),
}),
replaceBeforeSaveFile({
// this only works for the react-tooltip.css because it's the first file
// writen in our build process before the javascript files.
"'react-tooltip-css-placeholder'": 'file:react-tooltip.css',
'"react-tooltip-css-placeholder"': 'file:react-tooltip.css',
"'react-tooltip-core-css-placeholder'": 'file:react-tooltip.css',
'"react-tooltip-core-css-placeholder"': 'file:react-tooltip.css',
}),
]
if (specificPlugins && specificPlugins.length) {
plugins.push(...specificPlugins)
}
return {
input,
output: {
file,
format,
name,
globals,
sourcemap: true,
banner,
},
external,
plugins,
}
},
)
export default config