forked from okta/okta-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
106 lines (100 loc) · 2.44 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 babel from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import cleanup from 'rollup-plugin-cleanup';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import pkg from "./package.json";
require('./env'); // set variables in process.env
const makeExternalPredicate = () => {
const externalArr = [
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {}),
];
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join("|")})($|/)`);
return id => pattern.test(id);
};
const extensions = ['js', 'jsx', 'ts', 'tsx'];
const input = 'src/index.ts';
const external = makeExternalPredicate();
const commonPlugins = [
typescript({
// eslint-disable-next-line node/no-unpublished-require
typescript: require('typescript'),
useTsconfigDeclarationDir: true
}),
replace({
'process.env.PACKAGE_NAME': JSON.stringify(process.env.PACKAGE_NAME),
'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION),
'process.env.AUTH_JS_MAJOR_VERSION': JSON.stringify(process.env.AUTH_JS_MAJOR_VERSION)
}),
cleanup({
extensions,
comments: 'none'
})
];
export default [
{
input,
external,
plugins: [
...commonPlugins,
babel({
babelrc: false,
babelHelpers: 'bundled',
presets: [
'@babel/preset-env',
'@babel/preset-react'
],
extensions
}),
terser()
],
output: {
format: 'umd',
file: 'dist/bundles/okta-react.umd.js',
sourcemap: true,
name: 'OktaReact',
exports: 'named',
globals: {
'react': 'React',
'react-router-dom': 'ReactRouterDOM',
'@okta/okta-auth-js': 'OktaAuth'
}
}
},
{
input: 'src/index.ts',
external,
plugins: [
...commonPlugins,
babel({
babelHelpers: 'runtime',
presets: [
'@babel/preset-env',
'@babel/preset-react'
],
plugins: [
'@babel/plugin-transform-runtime'
],
extensions
}),
],
output: [
{
format: 'cjs',
file: 'dist/bundles/okta-react.cjs.js',
exports: 'named',
sourcemap: true
},
{
format: 'esm',
file: 'dist/bundles/okta-react.esm.js',
exports: 'named',
sourcemap: true
}
]
}
];