forked from okta/okta-auth-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
92 lines (87 loc) · 2.15 KB
/
Copy pathrollup.config.js
File metadata and controls
92 lines (87 loc) · 2.15 KB
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
import replace from '@rollup/plugin-replace';
import alias from '@rollup/plugin-alias';
import cleanup from 'rollup-plugin-cleanup';
import typescript from 'rollup-plugin-typescript2';
import license from 'rollup-plugin-license';
import multiInput from 'rollup-plugin-multi-input';
import pkg from './package.json';
const path = require('path');
const makeExternalPredicate = (env) => {
const externalArr = [
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {}),
];
if (env === 'node') {
externalArr.push('crypto');
}
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return id => pattern.test(id);
};
const extensions = ['js', 'ts'];
const output = {
format: 'es',
exports: 'named',
sourcemap: true,
preserveModules: true,
// not using .mjs extension because it causes issues with Vite
// entryFileNames: '[name].mjs'
};
const getPlugins = (env) => {
return [
replace({
'SDK_VERSION': JSON.stringify(pkg.version),
'global.': 'window.',
preventAssignment: true
}),
(env === 'browser' && alias({
entries: [
{ find: /.\/node$/, replacement: './browser' }
]
})),
typescript({
// eslint-disable-next-line node/no-unpublished-require
typescript: require('typescript'),
tsconfigOverride: {
compilerOptions: {
sourceMap: true,
target: 'ES2017', // skip async/await transpile,
module: 'ES2020', // support dynamic import
declaration: false
}
}
}),
cleanup({
extensions,
comments: 'none'
}),
license({
banner: {
content: {
file: path.join(__dirname, 'scripts', 'license-template'),
}
}
}),
multiInput({
relative: 'lib/',
}),
];
};
export default ['browser', 'node'].map((type) => {
return {
input: [
'lib/index.ts',
'lib/myaccount/index.ts'
],
external: makeExternalPredicate(type),
plugins: getPlugins(type),
output: [
{
...output,
dir: `build/esm/${type}`,
}
]
};
});