-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
50 lines (42 loc) · 1.4 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
const path = require('path');
const commonjs = require('@rollup/plugin-commonjs');
const nodeResolve = require('@rollup/plugin-node-resolve');
const replace = require('rollup-plugin-replace');
const terser = require('@rollup/plugin-terser');
const typescript = require('@rollup/plugin-typescript');
const packageJson = require('./package.json');
const dependencies = Object.keys(packageJson.dependencies);
const peerDependencies = Object.keys(packageJson.peerDependencies);
const PRODUCT_NAME = 'keyknox';
const FORMAT = {
CJS: 'cjs',
ES: 'es',
UMD: 'umd',
};
const sourcePath = path.join(__dirname, 'src');
const outputPath = path.join(__dirname, 'dist');
const createEntry = format => ({
external: format === FORMAT.UMD ? peerDependencies : dependencies.concat(peerDependencies),
input: path.join(sourcePath, 'index.ts'),
output: {
format,
file: path.join(outputPath, `keyknox.${format}.js`),
name: 'Keyknox',
globals: {
'virgil-sdk': 'Virgil',
},
},
plugins: [
replace({
'process.env.PRODUCT_NAME': JSON.stringify(PRODUCT_NAME),
'process.env.PRODUCT_VERSION': JSON.stringify(packageJson.version),
}),
format === FORMAT.UMD && nodeResolve({ browser: true, preferBuiltins: false }),
format === FORMAT.UMD && commonjs(),
typescript({
exclude: ['**/*.test.ts'],
}),
terser(),
],
});
module.exports = Object.values(FORMAT).map(createEntry);