-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.js
58 lines (53 loc) · 1.33 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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import builtins from "rollup-plugin-node-builtins";
import globals from "rollup-plugin-node-globals";
import path from "path";
import { readFileSync } from "fs";
const isDev = process.env.NODE_ENV !== "production";
const pluginBinary = ({ src, distfolder = "./" }) => {
const { name, base } = path.parse(src);
return {
name: "fetch-binary",
resolveId (id) {
// skip usual import for 'path'
if (id === src) {
return id;
}
return null;
},
load(id) {
if (id === src) {
let distpath = path.join(distfolder, base);
if (distpath.startsWith("/")) {
distpath = `.${distpath}`;
}
return `export default "${distpath}";`;
}
return null;
},
generateBundle() {
this.emitFile({
type: "asset",
fileName: base,
source: readFileSync(src),
});
},
};
};
const distfolder = isDev && "/dist/" || "/";
export default [{
input: "zbar-wasi.js",
output: {
file: "dist/zbar-wasi.esm.js",
format: "esm",
sourcemap: isDev,
},
plugins: [
pluginBinary({ src: "./zbar.wasm", distfolder }),
commonjs(),
builtins(),
globals(),
resolve({ preferBuiltins: true, browser: true }),
],
}];