-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
67 lines (61 loc) · 1.94 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
import { createBabelInputPluginFactory } from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
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 dev = !!process.env.DEV
const analyzeBundle = !!process.env.ANALYZE_BUNDLE
const minimize = !!process.env.MINIMIZE
const babelPluginForUMDBundle = createBabelInputPluginFactory()
const babelPluginForESMBundle = createBabelInputPluginFactory()
const babelPluginOptions = { ...babelConfig, exclude: 'node_modules/**', babelHelpers: 'bundled' }
const plugins = [
size(),
filesize(),
dev && serve({ contentBase: ['dist', 'public'], host: '0.0.0.0', port: '8080' }),
analyzeBundle && visualize({ open: true }),
]
const mainBundle = {
input: 'src/keymapping_plugin.js',
external: ['@clappr/core'],
output: [
{
name: 'KeyMappingPlugin',
file: pkg.main,
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
},
minimize && {
name: 'KeyMappingPlugin',
file: 'dist/clappr-key-mapping-plugin.min.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
plugins: terser(),
},
],
plugins: [babelPluginForUMDBundle(babelPluginOptions), resolve(), commonjs(), ...plugins],
}
const esmBundle = {
input: 'src/keymapping_plugin.js',
external: ['@clappr/core', /@babel\/runtime/],
output: {
name: 'KeyMappingPlugin',
file: pkg.module,
format: 'esm',
globals: { '@clappr/core': 'Clappr' },
},
plugins: [
babelPluginForESMBundle({
...babelPluginOptions,
plugins: ['@babel/plugin-transform-runtime'],
babelHelpers: 'runtime',
}),
...plugins,
],
}
export default [mainBundle, esmBundle]