-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
115 lines (106 loc) · 3.18 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
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
import { createBabelInputPluginFactory } from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import image from '@rollup/plugin-image'
import html from 'rollup-plugin-html'
import postcss from 'rollup-plugin-postcss'
import serve from 'rollup-plugin-serve'
import filesize from 'rollup-plugin-filesize'
import size from 'rollup-plugin-sizes'
import visualize from 'rollup-plugin-visualizer'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
import babelConfig from './babel.config.json'
const minimize = !!process.env.MINIMIZE
const babelPluginForUMDBundle = createBabelInputPluginFactory()
const babelPluginForESMBundle = createBabelInputPluginFactory()
const babelPluginOptions = { ...babelConfig, exclude: 'node_modules/**', babelHelpers: 'bundled' }
const plugins = [
image({ dom: true }),
html(),
postcss(),
size(),
filesize(),
!!process.env.DEV && serve({ contentBase: ['dist', 'public'], host: '0.0.0.0', port: '8080' }),
!!process.env.ANALYZE_BUNDLE && visualize({ open: true }),
]
const mainBundle = {
input: 'src/main.js',
external: ['@clappr/core'],
output: [
{
name: 'MediaControl',
file: pkg.main,
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
},
minimize && {
name: 'MediaControl',
file: 'dist/clappr-media-control-plugin.min.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
plugins: terser(),
},
],
plugins: [babelPluginForUMDBundle(babelPluginOptions), resolve(), commonjs(), ...plugins],
}
const esmBundle = {
input: 'src/main.js',
external: ['@clappr/core', /@babel\/runtime/],
output: {
name: 'MediaControl',
file: pkg.module,
format: 'esm',
globals: { '@clappr/core': 'Clappr' },
},
plugins: [
babelPluginForESMBundle({
...babelPluginOptions,
plugins: ['@babel/plugin-transform-runtime'],
babelHelpers: 'runtime',
}),
...plugins,
],
}
const lightBundle = {
input: 'src/light_bundle.js',
external: ['@clappr/core'],
output: [
{
name: 'MediaControl',
file: 'dist/light-clappr-media-control-plugin.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
},
minimize && {
name: 'MediaControl',
file: 'dist/light-clappr-media-control-plugin.min.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
plugins: terser(),
},
],
plugins: [babelPluginForUMDBundle(babelPluginOptions), resolve(), commonjs(), ...plugins],
}
const lightEsmBundle = {
input: 'src/light_bundle.js',
external: ['@clappr/core', /@babel\/runtime/],
output: {
name: 'MediaControl',
file: 'dist/light-clappr-media-control-plugin.esm.js',
format: 'esm',
globals: { '@clappr/core': 'Clappr' },
},
plugins: [
babelPluginForESMBundle({
...babelPluginOptions,
plugins: ['@babel/plugin-transform-runtime'],
babelHelpers: 'runtime',
}),
...plugins,
],
}
const mainBundles = [mainBundle, esmBundle]
const lightBundles = [lightBundle, lightEsmBundle]
const bundles = minimize ? [...mainBundles, ...lightBundles] : [...mainBundles]
export default bundles