-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
73 lines (64 loc) · 2.19 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
import os from 'os'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import sourceMaps from 'rollup-plugin-sourcemaps'
import camelCase from 'lodash.camelcase'
import snakeCase from 'lodash.snakecase'
import typescript from 'rollup-plugin-typescript2'
import {terser} from 'rollup-plugin-terser'
import nodeGlobals from 'rollup-plugin-node-globals'
import nodeBuiltins from '@joseph184/rollup-plugin-node-builtins'
import replace from 'rollup-plugin-replace'
import builtins from 'builtin-modules/static'
const pkg = require('./package.json')
const libraryName = pkg.name.slice(pkg.name.indexOf('/') + 1)
const libVarName = snakeCase(libraryName) + '_lib'
const varName = camelCase(libraryName)
const libClassName = `${varName[0].toUpperCase() + varName.slice(1)}` // PascalCase
const input = `src/${libClassName}.ts`
const watch = {include: 'src/**'}
const isProd = process.env.BUILD === 'production'
const uglify = process.env.UGLIFY
const plugins = [
replace({
include: [
'src/**/*.ts',
],
delimiters: ['<@', '@>'],
values: {
MODULE_NAME: libraryName, //JSON.stringify(libraryName)
},
}),
typescript({
useTsconfigDeclarationDir: true,
cacheRoot: `${os.tmpdir()}/.rpt2_cache`, // See: https://github.com/ezolenko/rollup-plugin-typescript2/issues/34#issuecomment-332591290
}),
commonjs(),
(uglify === 'true' || uglify !== 'false' && isProd) && terser(),
sourceMaps(),
]
const bundledOutput = {
input: input,
output: [
{format: 'umd', file: pkg.bundle, name: libVarName, sourcemap: true, exports: 'named'},
{format: 'esm', file: pkg["bundle-module"], sourcemap: true},
],
watch: watch,
plugins: [...plugins,
nodeGlobals(),
nodeBuiltins(),
resolve(),
],
}
const externals = [...builtins, ...Object.keys(pkg.dependencies || {})]
const globals = {}
externals.map(key => globals[key] = /[-.]/.test(key) ? camelCase(key) : key)
const dependentOutput = {
input: input,
output: {format: 'umd', file: pkg.main, name: libVarName, sourcemap: true, exports: 'named', globals: globals},
watch: watch,
external: externals,
plugins: plugins,
}
// noinspection JSUnusedGlobalSymbols
export default isProd ? [dependentOutput, bundledOutput] : dependentOutput