-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.js
81 lines (75 loc) · 2.2 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
import alias from '@rollup/plugin-alias'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { babel } from '@rollup/plugin-babel'
// packages
import webPkg from './packages/web/package.json'
import workerPkg from './packages/worker/package.json'
const bannersParams = {
web: webPkg,
worker: workerPkg
}
const LIBRARY_NAME = 'CableSW' // Library name
const EXTERNAL = [] // external modules
const GLOBALS = {} // https://rollupjs.org/guide/en/#outputglobals
const OUTPUT_DIR = 'dist'
const makeConfig = () => {
const configs = Object.keys(bannersParams).map((name) => {
const banner = `/*!
* ${bannersParams[name].name}
* ${bannersParams[name].description}
*
* @version v${bannersParams[name].version}
* @author ${bannersParams[name].author}
* @homepage ${bannersParams[name].homepage}
* @repository ${bannersParams[name].repository}
* @license ${bannersParams[name].license}
*/`
return {
input: `packages/${name}/src/index.js`,
external: EXTERNAL,
output: [
{
banner,
name: LIBRARY_NAME,
file: `packages/${name}/${OUTPUT_DIR}/index.umd.js`, // UMD
format: 'umd',
exports: 'auto',
globals: GLOBALS,
sourcemap: true
},
{
banner,
file: `packages/${name}/${OUTPUT_DIR}/index.cjs.js`, // CommonJS
format: 'cjs',
exports: 'named', // https://rollupjs.org/guide/en/#outputexports
globals: GLOBALS,
sourcemap: true
},
{
banner,
file: `packages/${name}/${OUTPUT_DIR}/index.esm.js`, // ESM
format: 'es',
exports: 'auto',
globals: GLOBALS,
sourcemap: true
}
],
plugins: [
alias({
entries: [{ find: /^cable-shared\/(.*)/, replacement: './shared/$1.js' }]
}),
resolve(), // teach Rollup how to find external modules
commonjs(), // so Rollup can convert external modules to an ES module
babel({
babelHelpers: 'bundled',
exclude: ['node_modules/**']
})
]
}
})
return configs
}
export default () => {
return makeConfig()
}