-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
93 lines (87 loc) · 2.73 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
import { createBabelInputPluginFactory } from '@rollup/plugin-babel'
import alias from '@rollup/plugin-alias'
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 namedDirectory from 'rollup-plugin-named-directory'
import size from 'rollup-plugin-sizes'
import visualize from 'rollup-plugin-visualizer'
import { terser } from 'rollup-plugin-terser'
import babelConfig from './babel.config.json'
const babelPluginForUMDBundle = createBabelInputPluginFactory()
const babelPluginForESMBundle = createBabelInputPluginFactory()
const babelPluginOptions = { ...babelConfig, exclude: 'node_modules/**', babelHelpers: 'bundled' }
const aliasPluginOptions = { entries: { '@': `${__dirname}/src` } }
const plugins = [
alias(aliasPluginOptions),
namedDirectory(),
size(),
filesize(),
!!process.env.DEV && serve({ contentBase: ['dist', 'public'], host: '0.0.0.0', port: '8080' }),
!!process.env.ANALYZE_BUNDLE && visualize({ open: true }),
]
const browserBundle = {
input: 'src/ima-parser.js',
external: ['@clappr/core'],
output: [
{
name: 'IMAParser',
exports: 'named',
file: 'dist/clappr-ima-parser.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
},
!!process.env.MINIMIZE && {
name: 'IMAParser',
exports: 'named',
file: 'dist/clappr-ima-parser.min.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
plugins: terser(),
},
],
plugins: [babelPluginForUMDBundle(babelPluginOptions), resolve({ browser: true }), commonjs(), ...plugins],
}
const nodeBundle = {
input: 'src/ima-parser.js',
external: ['@clappr/core'],
output: [
{
name: 'IMAParser',
exports: 'named',
file: 'dist/clappr-ima-parser-node.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
},
!!process.env.MINIMIZE && {
name: 'IMAParser',
exports: 'named',
file: 'dist/clappr-ima-parser-node.min.js',
format: 'umd',
globals: { '@clappr/core': 'Clappr' },
plugins: terser(),
},
],
plugins: [babelPluginForUMDBundle(babelPluginOptions), resolve(), commonjs(), ...plugins],
}
const esmBundle = {
input: 'src/ima-parser.js',
external: ['@clappr/core', /@babel\/runtime/],
output: {
name: 'IMAParser',
exports: 'named',
file: 'dist/clappr-ima-parser.esm.js',
format: 'esm',
globals: { '@clappr/core': 'Clappr' },
},
plugins: [
babelPluginForESMBundle({
...babelPluginOptions,
plugins: ['@babel/plugin-transform-runtime'],
babelHelpers: 'runtime',
}),
...plugins,
],
}
export default [browserBundle, nodeBundle, esmBundle]