-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
106 lines (94 loc) · 2.51 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
97
98
99
100
101
102
103
104
105
106
import sourceMaps from 'rollup-plugin-sourcemaps'
import nodeResolve from 'rollup-plugin-node-resolve'
import json from 'rollup-plugin-json'
import commonjs from 'rollup-plugin-commonjs'
import replace from 'rollup-plugin-replace'
import { uglify } from 'rollup-plugin-uglify'
import { terser } from 'rollup-plugin-terser'
import { getIfUtils, removeEmpty } from 'webpack-config-utils'
import pkg from './package.json'
/**
* @typedef {import('./types').RollupConfig} Config
*/
/**
* @typedef {import('./types').RollupPlugin} Plugin
*/
const env = process.env.NODE_ENV || 'development'
const { ifProduction } = getIfUtils(env)
const libraryName = 'trackable-entities'
/**
* @type {string[]}
*/
const external = Object.keys(pkg.peerDependencies) || []
/**
* @type {Plugin[]}
*/
const plugins = /** @type {Plugin[]} */ ([
// Allow json resolution
json(),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
nodeResolve(),
// Resolve source maps to the original source
sourceMaps(),
// properly set process.env.NODE_ENV within `./environment.ts`
replace({
exclude: 'node_modules/**',
'process.env.NODE_ENV': JSON.stringify(env),
}),
])
/**
* @type {Config}
*/
const CommonConfig = {
input: {},
output: {},
inlineDynamicImports: true,
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external,
}
/**
* @type {Config}
*/
const UMDconfig = {
...CommonConfig,
// input: resolve(PATHS.entry.compiled, `${libraryName}.js`),
input: `dist/compiled/${libraryName}.js`,
output: {
file: `dist/bundles/${libraryName}.umd.js`,
format: 'umd',
name: libraryName,
sourcemap: true,
globals: {
'tslib': 'TypeScriptLib'
}
},
plugins: removeEmpty(
/** @type {Plugin[]} */ ([...plugins, ifProduction(uglify())])
),
}
/**
* @type {Config}
*/
const FESMconfig = {
...CommonConfig,
// input: resolve(PATHS.entry.compiled, `${libraryName}.js`),
input: `dist/compiled/${libraryName}.js`,
output: [
{
file: `dist/bundles/${libraryName}.es2015.js`,
format: 'es',
sourcemap: true,
globals: {
'tslib': 'TypeScriptLib'
}
},
],
plugins: removeEmpty(
/** @type {Plugin[]} */ ([...plugins, ifProduction(terser())])
),
}
export default [UMDconfig, FESMconfig]