-
Notifications
You must be signed in to change notification settings - Fork 67
/
rollup.config.js
96 lines (83 loc) · 2.53 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
import pkg from './package.json'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import filesize from 'rollup-plugin-filesize'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import typescript from 'rollup-plugin-typescript2'
import visualizer from 'rollup-plugin-visualizer'
import fs from 'fs'
import nodeEval from 'node-eval'
const extensions = [
'.js', '.jsx', '.ts', '.tsx', 'json',
]
export function getModuleExports(moduleId) {
const id = require.resolve(moduleId)
const moduleOut = nodeEval(fs.readFileSync(id).toString(), id)
let result = []
const excludeExports = /^(default|__)/
if (moduleOut && typeof moduleOut === 'object') {
result = Object.keys(moduleOut)
.filter((name) => !excludeExports.test(name))
}
return result
}
// Helper for getting the names exports automagically
export function getNamedExports(moduleIds) {
const result = {}
moduleIds.forEach( (id) => {
result[id] = getModuleExports(id)
})
return result
}
const plugins = [
peerDepsExternal(),
resolve({
extensions,
preferBuiltins: true,
}),
json({
// All JSON files will be parsed by default,
// but you can also specifically include/exclude files
include: 'node_modules/**',
// for tree-shaking, properties will be declared as
// variables, using either `var` or `const`
preferConst: true, // Default: false
// specify indentation for the generated default export —
// defaults to '\t'
indent: ' ',
// ignores indent and generates the smallest code
compact: true, // Default: false
// generate a named export for every property of the JSON object
namedExports: true // Default: true
}),
typescript(),
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/react-is/index.js': ['isFragment', 'ForwardRef', 'Memo'],
'node_modules/prop-types/index.js': ['elementType'],
'node_modules/react-virtualized/dist/es/WindowScroller/WindowScroller.js': ['bpfrpt_proptype_WindowScroller'],
}
}),
filesize(),
visualizer(),
]
export default [
// source
{
input: 'src/index.ts',
external: ['cross-fetch'],
plugins,
output: [
{
name: pkg.name, file: pkg.browser, format: 'umd', sourcemap: true,
globals: {
'cross-fetch': 'fetch',
},
},
// { file: pkg.main, format: 'cjs', sourcemap: true },
// { file: pkg.module, format: 'es', sourcemap: true },
],
},
]