forked from undecaf/barcode-detector-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
113 lines (103 loc) · 3.28 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
import license from 'rollup-plugin-license'
import pkg from './package.json'
import pkgLock from './package-lock.json'
import replace from '@rollup/plugin-replace'
import ts from 'rollup-plugin-ts'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import { terser } from 'rollup-plugin-terser'
const ZBAR_WASM_PKG_NAME = '@undecaf/zbar-wasm'
const ZBAR_WASM_VERSION = pkgLock.dependencies[ZBAR_WASM_PKG_NAME].version
const ZBAR_WASM_REPOSITORY = `https://cdn.jsdelivr.net/npm/${ZBAR_WASM_PKG_NAME}@${ZBAR_WASM_VERSION}`
const input = 'src/main.ts'
const replacePlugin = replace({
values: {
__ZBAR_WASM_PKG_NAME__: ZBAR_WASM_PKG_NAME,
__ZBAR_WASM_REPOSITORY__: ZBAR_WASM_REPOSITORY,
__ZBAR_WASM_VERSION__: ZBAR_WASM_VERSION,
},
preventAssignment: true,
})
const plugins = [
ts(),
nodeResolve(/*{ preferBuiltins: false }*/),
replacePlugin,
license(
{
sourcemap: true,
banner: {
content: `${pkg.name} v${pkg.version}
${pkg.description}
Built ${new Date().toISOString()}
(c) 2021-present Ferdinand Kasper <[email protected]>
Released under the MIT license.
This work uses https://github.com/undecaf/zbar-wasm.git as per
LGPL-2.1 section 6 (https://opensource.org/licenses/LGPL-2.1).`,
commentStyle: 'ignored',
},
thirdParty: {
allow: '(MIT OR 0BSD)',
},
}
),
terser(),
]
export default [
{
// Plain <script>
// '@undecaf/zbar-wasm' must be loaded from a repository at runtime, e.g. as
// <script src="https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm/dist/index.js></script>
input,
output: {
file: pkg.exports['.'].script,
format: 'iife',
generatedCode: 'es2015',
sourcemap: true,
globals: {
[ZBAR_WASM_PKG_NAME]: 'zbarWasm',
},
name: 'barcodeDetectorPolyfill',
},
external: [ZBAR_WASM_PKG_NAME],
plugins,
},
{
// ES module and <script type="module">
// '@undecaf/zbar-wasm' is imported from a repository at runtime
input,
output: {
file: pkg.exports['.'].default,
format: 'esm',
generatedCode: 'es2015',
sourcemap: true,
paths: {
[ZBAR_WASM_PKG_NAME]: `${ZBAR_WASM_REPOSITORY}/dist/main.js`,
},
},
external: [ZBAR_WASM_PKG_NAME],
plugins,
},
{
// Provide metainformation on @undecaf/zbar-wasm as ES module for bundlers
input: './zbar-wasm.meta.js',
output: {
file: pkg.exports['./zbar-wasm'].default,
format: 'esm',
},
plugins: [
replacePlugin,
terser(),
],
},
{
// Provide metainformation on @undecaf/zbar-wasm as CommonJS module for bundlers
input: './zbar-wasm.meta.js',
output: {
file: pkg.exports['./zbar-wasm'].require,
format: 'cjs',
},
plugins: [
replacePlugin,
terser(),
],
},
]