-
Notifications
You must be signed in to change notification settings - Fork 9
/
rollup.config.js
93 lines (85 loc) · 2.36 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
import replace from '@rollup/plugin-replace';
import autoExternal from 'rollup-plugin-auto-external';
import path from 'path';
import * as plugins from './rollup/plugins';
import { getGlobalName, getFileName } from './rollup/utils';
const { LERNA_PACKAGE_NAME } = process.env;
const PACKAGE_ROOT_PATH = process.cwd();
const INPUT_FILE = path.join(PACKAGE_ROOT_PATH, 'src/index.js');
const globals = {
validarium: 'Validarium',
'@validarium/core': 'ValidariumCore',
'@validarium/intl': 'ValidariumIntl',
'@validarium/validations': 'ValidariumValidations',
'@validarium/predicates': 'ValidariumPredicates',
invariant: 'invariant',
ramda: 'R',
'ramda-extension': 'R_',
};
const globalName = getGlobalName(LERNA_PACKAGE_NAME);
const fileName = getFileName(LERNA_PACKAGE_NAME);
export default [
// CJS
{
input: INPUT_FILE,
external: x => x.includes('ramda'),
output: {
file: path.join(PACKAGE_ROOT_PATH, 'lib', `${fileName}.js`),
format: 'cjs',
indent: false,
},
plugins: [autoExternal(), plugins.nodeResolve, plugins.babel('cjs'), plugins.cjs],
},
// ES
{
input: INPUT_FILE,
external: x => x.includes('ramda'),
output: {
file: path.join(PACKAGE_ROOT_PATH, 'es', `${fileName}.js`),
format: 'es',
indent: false,
},
plugins: [autoExternal(), plugins.nodeResolve, plugins.babel('es'), plugins.cjs],
},
// UMD Development
{
input: INPUT_FILE,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'dist', `${fileName}.js`),
format: 'umd',
name: globalName,
indent: false,
globals,
},
// external: x => x.includes('ramda'),
plugins: [
// Bundle all in one file for umd distribution for `validarium` package
...(globalName === 'Validarium' ? [] : [autoExternal()]),
// autoExternal(),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
plugins.nodeResolve,
plugins.babel('umd'),
plugins.cjs,
],
},
// UMD Production
{
input: INPUT_FILE,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'dist', `${fileName}.min.js`),
format: 'umd',
name: globalName,
indent: false,
globals,
},
plugins: [
// Bundle all in one file for umd distribution for `validarium` package
...(globalName === 'Validarium' ? [] : [autoExternal()]),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
plugins.nodeResolve,
plugins.babel('umd'),
plugins.cjs,
plugins.terser,
],
},
];