forked from VirgilSecurity/virgil-e3kit-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
97 lines (88 loc) · 2.64 KB
/
rollup.config.js
File metadata and controls
97 lines (88 loc) · 2.64 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
93
94
95
96
97
const path = require('path');
const commonjs = require('rollup-plugin-commonjs');
const inject = require('rollup-plugin-inject');
const nodeGlobals = require('rollup-plugin-node-globals');
const resolve = require('rollup-plugin-node-resolve');
const typescript = require('rollup-plugin-typescript2');
const { uglify } = require('rollup-plugin-uglify');
const sourcemap = require('rollup-plugin-sourcemaps');
const noPythiaCryptoPath = require.resolve('virgil-crypto');
const pythiaCryptoPath = path.resolve(noPythiaCryptoPath, '../virgil-crypto-pythia.cjs.js');
const pythiaCryptoBrowserPath = path.resolve(noPythiaCryptoPath, '../virgil-crypto-pythia.browser.cjs.js');
const packageJson = require('./package.json');
const NAME = 'e3kit';
const UMD_NAME = 'E3kit';
const env = process.env.ENV;
const format = process.env.FORMAT;
const minify = process.env.MINIFY === 'true';
const browser = 'browser';
const node = 'node';
const cjs = 'cjs';
const es = 'es';
const umd = 'umd';
const environment = {
[browser]: {
[cjs]: cjs,
[es]: es,
[umd]: umd,
},
[node]: {
[cjs]: cjs,
[es]: es,
},
};
if (!environment[env]) {
throw new TypeError(`'${env}' is not a valid environment`);
} else if (!environment[env][format]) {
throw new TypeError(`'${format}' is not a valid module format for '${env}' environment`);
}
let external = []
if (format !== umd) {
external = external.concat(Object.keys(packageJson.dependencies)).concat('virgil-crypto/dist/virgil-crypto-pythia.cjs');
}
function getFileName(name, environment, format, isMinified) {
const parts = [name, environment, format];
if (isMinified) {
parts.push('min');
}
parts.push('js');
return parts.join('.');
}
function resolveVirgilCrypto (isBrowser) {
return {
name: 'resolve-virgil-crypto',
resolveId (importee, importer) {
if (importee === 'virgil-crypto') {
return isBrowser ? pythiaCryptoBrowserPath : pythiaCryptoPath;
}
}
}
}
module.exports = {
external,
input: path.join(__dirname, 'src', 'index.ts'),
output: {
format,
file: getFileName(NAME, env, format, minify),
dir: path.join(__dirname, 'dist'),
sourceMap: true,
name: UMD_NAME
},
plugins: [
sourcemap(),
resolveVirgilCrypto({ browser: format === umd }),
resolve({ browser: format === umd }),
commonjs(),
typescript({
exclude: ['**/*.test.ts', '**/*.spec.ts', '**/__mocks__/*.ts'],
useTsconfigDeclarationDir: true,
}),
env === browser && inject({
modules: {
Buffer: ['buffer-es6', 'Buffer'],
},
}),
env === browser && nodeGlobals(),
minify && uglify(),
],
};