-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
rollup.config.js
73 lines (68 loc) · 1.93 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 commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { babel } from '@rollup/plugin-babel';
import banner from 'rollup-plugin-banner';
// import eslint from '@rollup/plugin-eslint';
const { terser } = require('rollup-plugin-terser');
const path = require('path');
const production = !process.env.BUILD || (process.env.BUILD === 'prod');
const inputPath = 'src/index.js';
const outputPath = (format, minify = false) => `lib/${format}/bundle${minify ? '.min' : ''}.js`;
const packageName = 'rpgDiceRoller';
const globals = {
mathjs: 'math',
'random-js': 'Random',
};
/**
* Returns a list of common plugins
*
* @param {boolean} [isUmd=false]
* @param {boolean} [isProduction=false]
* @returns {{}}
*/
const plugins = (isUmd = false, isProduction = false) => [
// lint the files (Currently broken because plugin uses an old version of eslint)
// eslint(),
// resolve third party library imports
nodeResolve(),
// handle commonJS modules
commonjs(),
// only use babel if we're compiling to UMD
isUmd ? babel({
exclude: 'node_modules/**',
}) : null,
// minify for production
isProduction ? terser({ keep_classnames: true }) : null,
banner({
file: path.join(__dirname, 'banner.txt'),
}),
];
export default [
// ESM
{
input: inputPath,
output: {
file: outputPath('esm', production),
format: 'esm',
// map external dependencies to variables
globals,
},
plugins: plugins(false, production),
// indicate which modules should be treated as external
external: ['mathjs'],
},
// UMD
{
input: inputPath,
output: {
file: outputPath('umd', production),
format: 'umd',
name: packageName,
// map external dependencies to variables
globals,
},
plugins: plugins(true, production),
// indicate which modules should be treated as external
external: ['mathjs', 'random-js'],
},
];