-
Notifications
You must be signed in to change notification settings - Fork 10
/
rollup.config.js
65 lines (58 loc) · 1.66 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
const path = require('path');
const builtinModules = require('builtin-modules');
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-typescript2');
const packageJson = require('./package.json');
const FORMAT = {
CJS: 'cjs',
ES: 'es',
UMD: 'umd',
};
const sourcePath = path.join(__dirname, 'src');
const outputPath = path.join(__dirname, 'dist');
const input = path.join(sourcePath, 'index.ts');
const createEntry = (format, isBrowser) => {
let filename = 'virgil-sdk';
if (isBrowser) {
filename += '.browser';
}
filename += `.${format}.js`;
let tsconfigOverride = format === FORMAT.ES ? { compilerOptions: { target: 'es2015' } } : {};
return {
external: builtinModules.concat(isBrowser ? [] : Object.keys(packageJson.dependencies)),
input,
output: {
format,
file: path.join(outputPath, filename),
name: 'Virgil',
},
plugins: [
isBrowser && nodeResolve({
browser: true,
extensions: ['.ts', '.js']
}),
isBrowser && commonjs(),
replace({
'process.browser': JSON.stringify(isBrowser),
'process.env.VERSION': JSON.stringify(packageJson.version),
}),
typescript({
typescript: require('typescript'),
exclude: ['**/*.test.ts'],
useTsconfigDeclarationDir: true,
tsconfigOverride,
}),
format === FORMAT.UMD && terser(),
].filter(Boolean),
};
};
module.exports = [
createEntry(FORMAT.CJS),
createEntry(FORMAT.ES),
createEntry(FORMAT.CJS, true),
createEntry(FORMAT.ES, true),
createEntry(FORMAT.UMD, true),
];