This repository has been archived by the owner on Jun 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
60 lines (53 loc) · 1.78 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
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 typescript from 'rollup-plugin-typescript2'
import {terser} from 'rollup-plugin-terser'
import os from 'os'
import autoExternal from 'rollup-plugin-auto-external'
import globals from 'rollup-plugin-node-globals'
import builtins from 'rollup-plugin-node-builtins'
const pkg = require('./package.json')
const libraryName = pkg.name.slice(pkg.name.indexOf('/') + 1)
const libVarName = camelCase(libraryName)
const libClassName = `${libVarName[0].toUpperCase() + libVarName.slice(1)}` // PascalCase
const input = `src/${libClassName}.ts`
const watch = {include: 'src/**'}
const isProd = process.env.BUILD === 'production'
const uglify = process.env.UGLIFY
const commonPlugins = [
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: commonPlugins.concat([
globals(),
builtins(),
resolve(),
]),
}
const dependentOutput = {
input: input,
output: {
format: 'umd', file: pkg.main, name: libVarName, sourcemap: true, exports: 'named',
globals: {debug: 'Debug'}
},
watch: watch,
plugins: commonPlugins.concat([
autoExternal(),
]),
}
// noinspection JSUnusedGlobalSymbols
export default isProd ? [dependentOutput, bundledOutput] : dependentOutput