-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup-umd.config.js
59 lines (55 loc) · 2.15 KB
/
rollup-umd.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
import replace from 'rollup-plugin-replace'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import json from 'rollup-plugin-json'
import {eslint} from 'rollup-plugin-eslint'
import formatter from 'eslint-friendly-formatter'
import babel from 'rollup-plugin-babel'
import {uglify} from 'rollup-plugin-uglify'
import builtins from 'rollup-plugin-node-builtins'
import globals from 'rollup-plugin-node-globals'
import visualizer from 'rollup-plugin-visualizer'
import pkg from './package.json'
function umdConfig(name) {
return {
input: 'lib/index.js',
output: {
name: 'LemoClient',
file: `dist/${name}`,
format: 'umd',
},
plugins: [
replace({
'process.browser': 'true',
// use esm version to support tree-shaking
'lemo-utils': 'lemo-utils/dist/lemo-utils.esm.js',
'lemo-tx': 'lemo-tx/dist/lemo-tx.esm.js',
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.SDK_VERSION': JSON.stringify(pkg.version),
}),
// use resolve so Rollup can find external libraries
// set browser to true so we could load the 'browser' field of libraries' package.json
resolve({browser: true, preferBuiltins: true}),
// use commonjs so Rollup can convert external libraries to an ES module
commonjs(),
babel({
// transform es6 code. This needs @babel/plugin-transform-runtime and @babel/runtime
runtimeHelpers: true,
exclude: 'node_modules/**',
}),
json(),
globals({process: false, dirname: false, filename: false}),
builtins(),
],
}
}
const umdVersion = umdConfig('lemo-client.js')
// eslint should before babel
umdVersion.plugins.unshift(eslint({formatter}))
umdVersion.plugins.push(visualizer({filename: 'file_size_visualizer.html'}))
const umdMinVersion = umdConfig('lemo-client.min.js')
umdMinVersion.plugins.push(uglify())
export default [
umdVersion,
umdMinVersion,
]