forked from clauderic/react-sortable-hoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
89 lines (82 loc) · 2.06 KB
/
rollup.config.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
import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import filesize from 'rollup-plugin-filesize';
import {uglify} from 'rollup-plugin-uglify';
import pkg from './package.json';
const external = (id) => !id.startsWith('.') && !id.startsWith('/');
const babelConfig = (
{useESModules, targets} = {
useESModules: true,
targets: {browsers: 'last 2 versions'},
},
) => ({
comments: false,
runtimeHelpers: true,
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets,
},
],
],
plugins: [
'@babel/plugin-proposal-class-properties',
['@babel/transform-runtime', {useESModules, regenerator: false}],
['babel-plugin-transform-async-to-promises', {inlineHelpers: true}],
],
exclude: 'node_modules/**',
});
const umdConfig = ({minify} = {}) => ({
input: pkg.source,
external: ['react', 'react-dom', 'prop-types'],
output: {
name: 'SortableHOC',
file: minify ? pkg["umd:main"].replace('.js', '.min.js') : pkg["umd:main"],
format: 'umd',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
},
},
plugins: [
resolve(),
babel(
babelConfig({
targets: {browsers: ['last 2 versions', 'safari >= 7']},
}),
),
replace({
'process.env.NODE_ENV': JSON.stringify(
minify ? 'production' : 'development',
),
}),
commonjs(),
minify ? uglify() : { },
filesize(),
],
});
const rollupConfig = [
// Browser-friendly UMD builds
umdConfig(),
umdConfig({minify: true}),
// CommonJS
{
input: pkg.source,
external,
output: [{file: pkg.main, format: 'cjs'}],
plugins: [resolve(), babel(babelConfig({useESModules: false})), filesize()],
},
// ES module
{
input: pkg.source,
external,
output: [{file: pkg.module, format: 'esm'}],
plugins: [resolve(), babel(babelConfig()), filesize()],
},
];
export default rollupConfig;