-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.ts
83 lines (76 loc) · 2.25 KB
/
rollup.config.ts
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
import ts from 'rollup-plugin-typescript2'
import {terser} from 'rollup-plugin-terser'
import dts from 'rollup-plugin-dts'
import {OutputOptions, RollupOptions} from 'rollup'
import del from 'rollup-plugin-delete'
import analyze from 'rollup-plugin-analyzer'
import gzipPlugin from 'rollup-plugin-gzip'
// This suppresses warning when using custom flag (--analyze)
const onwarn: RollupOptions['onwarn'] = function onwarn(warning, warn) {
if (
warning.code === 'UNKNOWN_OPTION' &&
['analyze', 'mingzip']
.some(flag => warning.message.startsWith(`Unknown CLI flags: ${flag}`))
) {
return
}
warn(warning)
}
export default (cliOptions: any) => {
const buildPlugins = [
del({targets: 'lib/*'}),
ts({
useTsconfigDeclarationDir: true
}),
]
if (cliOptions.analyze) {
buildPlugins.push(analyze({summaryOnly: true}))
}
if (cliOptions.mingzip) {
buildPlugins.push(gzipPlugin({filter: /bundle\.min\.js/}))
}
const output: OutputOptions[] = [
{file: "lib/bundle.cjs", format: "cjs", sourcemap: true},
{file: "lib/bundle.js", format: "es", sourcemap: true},
]
if(cliOptions.mingzip) {
output.push({file: "lib/bundle.min.js", format: "umd", name: "unique_tslib", sourcemap: true, plugins: [terser()]})
}
const options: RollupOptions[] = [
{
input: './src/index.ts',
output,
//[
// {
// file: "lib/bundle.umd.min.js",
// name: "unique",
// format: "umd",
// plugins: [
// // terser()
// ],
// globals: {
// '@polkadot/util': 'polkadotUtil',
// '@polkadot/util-crypto': 'polkadotUtilCrypto',
// '@polkadot/extension-dapp': 'polkadotExtensionDapp',
// '@polkadot/api': 'polkadotApi',
// 'ethers': 'ethers',
// },
// sourcemap: true,
// },
// ],
// external: ['@polkadot/util-crypto', '@polkadot/api']
plugins: buildPlugins,
onwarn,
},
{
input: "./lib/dts/src/index.d.ts",
output: [{file: "lib/bundle.d.ts", format: "es"}],
plugins: [
dts(),
del({hook: "buildEnd", targets: ["./lib/dts", "./lib/bundle.d.ts.map"]}),
],
onwarn,
},
]
return options
}