forked from openpgpjs/openpgpjs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
126 lines (118 loc) · 4.1 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* eslint-disable no-process-env */
import { builtinModules } from 'module';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
const nodeDependencies = Object.keys(pkg.dependencies);
const banner =
`/*! OpenPGP.js v${pkg.version} - ` +
`${new Date().toISOString().split('T')[0]} - ` +
`this is LGPL licensed code, see LICENSE/our website ${pkg.homepage} for more information. */`;
const intro = "const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};";
const terserOptions = {
ecma: 2017,
compress: {
unsafe: true
},
output: {
comments: '/^(?:!|#__)/',
preserve_annotations: true
}
};
export default Object.assign([
{
input: 'src/index.js',
output: [
{ file: 'dist/openpgp.js', format: 'iife', name: pkg.name, banner, intro },
{ file: 'dist/openpgp.min.js', format: 'iife', name: pkg.name, banner, intro, plugins: [terser(terserOptions)], sourcemap: true },
{ file: 'dist/openpgp.mjs', format: 'es', banner, intro },
{ file: 'dist/openpgp.min.mjs', format: 'es', banner, intro, plugins: [terser(terserOptions)], sourcemap: true }
],
inlineDynamicImports: true,
plugins: [
resolve({
browser: true
}),
commonjs({
ignore: builtinModules.concat(nodeDependencies)
}),
replace({
'OpenPGP.js VERSION': `OpenPGP.js ${pkg.version}`,
'require(': 'void(',
delimiters: ['', '']
})
]
},
{
input: 'src/index.js',
inlineDynamicImports: true,
external: builtinModules.concat(nodeDependencies),
output: [
{ file: 'dist/node/openpgp.js', format: 'cjs', name: pkg.name, banner, intro },
{ file: 'dist/node/openpgp.min.js', format: 'cjs', name: pkg.name, banner, intro, plugins: [terser(terserOptions)], sourcemap: true },
{ file: 'dist/node/openpgp.mjs', format: 'es', banner, intro },
{ file: 'dist/node/openpgp.min.mjs', format: 'es', banner, intro, plugins: [terser(terserOptions)], sourcemap: true }
],
plugins: [
resolve(),
commonjs(),
replace({
'OpenPGP.js VERSION': `OpenPGP.js ${pkg.version}`
})
]
},
{
input: 'src/index.js',
output: [
{ dir: 'dist/lightweight', entryFileNames: 'openpgp.mjs', chunkFileNames: '[name].mjs', format: 'es', banner, intro },
{ dir: 'dist/lightweight', entryFileNames: 'openpgp.min.mjs', chunkFileNames: '[name].min.mjs', format: 'es', banner, intro, plugins: [terser(terserOptions)], sourcemap: true }
],
preserveEntrySignatures: 'allow-extension',
plugins: [
resolve({
browser: true
}),
commonjs({
ignore: builtinModules.concat(nodeDependencies)
}),
replace({
'OpenPGP.js VERSION': `OpenPGP.js ${pkg.version}`,
'require(': 'void(',
delimiters: ['', '']
})
]
},
{
input: 'test/unittests.js',
output: [
{ file: 'test/lib/unittests-bundle.js', format: 'es', intro, sourcemap: true }
],
inlineDynamicImports: true,
external: ['../..', '../../..'],
plugins: [
resolve({
browser: true
}),
commonjs({
ignore: builtinModules.concat(nodeDependencies)
}),
replace({
"import openpgpjs from '../../..';": `import * as openpgpjs from '/dist/${process.env.npm_config_lightweight ? 'lightweight/' : ''}openpgp.mjs'; window.openpgp = openpgpjs;`,
'require(': 'void(',
delimiters: ['', '']
})
]
}
].filter(config => {
config.output = config.output.filter(output => {
return (output.file || output.dir + '/' + output.entryFileNames).includes(
process.env.npm_config_build_only || // E.g. `npm install --build-only=lightweight`.
'dist' // Don't build test bundle by default.
);
});
return config.output.length;
}), {
allow_empty: true // Fake option to trick rollup into accepting empty config array when filtered above.
});