forked from ReactTooltip/react-tooltip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.prod.js
104 lines (91 loc) · 2.62 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
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 pkg from './package.json'
const input = ['src/index.tsx']
const name = 'ReactTooltip'
const external = ['react', 'react-dom', 'prop-types']
const globals = {
react: 'React',
'react-dom': 'ReactDOM',
classnames: 'classNames',
'prop-types': 'PropTypes',
}
// splitted to be reusable by minified css build and unminified css
const pluginsBeforePostCSS = [
progress(),
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify('development'),
},
}),
]
// splitted to be reusable by minified css build and unminified css
const pluginsAfterPostCSS = [
nodeResolve(),
ts({
typescript,
tsconfig: './tsconfig.json',
noEmitOnError: false,
// declaration: true,
// declarationDir: './build',
}),
commonjs({
include: 'node_modules/**',
}),
]
const plugins = [
...pluginsBeforePostCSS,
postcss({
// extract: true, // this will generate a css file based on output file name
extract: '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: [],
}),
...pluginsAfterPostCSS,
]
const pluginsForCSSMinification = [
...pluginsBeforePostCSS,
postcss({
extract: 'react-tooltip.min.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: true,
}),
...pluginsAfterPostCSS,
]
const defaultOutputData = pkg.buildFormats.map(({ file, format }) => ({
file,
format,
plugins: [...plugins, filesize()],
}))
// this step is just to build the minified css and es modules javascript
const minifiedOutputData = pkg.buildFormats.map(({ file, format }) => ({
file: file.replace('.js', '.min.js'),
format,
plugins: [...pluginsForCSSMinification, terser(), filesize()],
}))
const outputData = [...minifiedOutputData, ...defaultOutputData]
const config = outputData.map(({ file, format, plugins: specificPLugins }) => ({
input,
output: {
file,
format,
name,
globals,
},
external,
plugins: specificPLugins,
}))
export default config