-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
101 lines (95 loc) · 2.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
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
import _ from 'lodash'
import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
const require = createRequire(import.meta.url)
const pkg = require('./package.json')
const externalDependencies = [
..._.keys(pkg.devDependencies),
'stream',
]
// good rollup example: https://github.com/MattiasBuelens/web-streams-polyfill/blob/master/rollup.config.js
const configs = [
// src/main.js
{
input: 'src/main.js',
plugins: [json(), nodeResolve({ browser: true }), commonjs()],
external: externalDependencies,
output: _.times(2, isMin => ({
file: 'dist/pn532.js',
format: 'umd',
name: 'Pn532',
globals: {
lodash: '_',
},
...(!isMin ? {} : { // for minify
file: 'dist/pn532.min.js',
plugins: [terser()],
}),
})),
},
// src/Crypto1.js
{
input: 'src/Crypto1.js',
plugins: [json(), nodeResolve({ browser: true }), commonjs()],
external: [
...externalDependencies,
fileURLToPath(new URL('src/Packet.js', import.meta.url)),
],
output: _.times(2, isMin => ({
file: 'dist/Crypto1.js',
format: 'umd',
name: 'Crypto1',
globals: {
lodash: '_',
[fileURLToPath(new URL('src/Packet.js', import.meta.url))]: 'Pn532.Packet',
},
...(!isMin ? {} : { // for minify
file: 'dist/Crypto1.min.js',
plugins: [terser()],
}),
})),
},
// src/Crypto1.js
{
input: 'src/Packet.js',
plugins: [json(), nodeResolve({ browser: true }), commonjs()],
external: externalDependencies,
output: _.times(2, isMin => ({
file: 'dist/Packet.js',
format: 'umd',
name: 'Packet',
globals: {
lodash: '_',
},
...(!isMin ? {} : { // for minify
file: 'dist/Packet.min.js',
plugins: [terser()],
}),
})),
},
// plugins
..._.map(['Hf14a', 'LoggerRxTx', 'SerialPortAdapter', 'WebbleAdapter', 'WebserialAdapter'], input => ({
input: `src/plugin/${input}.js`,
plugins: [json(), nodeResolve({ browser: true }), commonjs()],
external: externalDependencies,
output: _.times(2, isMin => ({
file: `dist/plugin/${input}.js`,
format: 'umd',
name: `Pn532${input}`,
globals: {
lodash: '_',
serialport: 'serialport',
stream: 'stream',
},
...(!isMin ? {} : { // for minify
file: `dist/plugin/${input}.min.js`,
plugins: [terser()],
}),
})),
})),
]
export default configs