-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
118 lines (110 loc) · 3.29 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
import dts from 'rollup-plugin-dts';
import esbuild from 'rollup-plugin-esbuild';
import nodeResolve from 'rollup-plugin-node-resolve';
import crypto from 'crypto';
import path from 'path';
import makeDir from 'make-dir';
import { createReadStream, createWriteStream } from 'fs';
function wasm() {
const fileNames = {};
return {
name: 'wasm',
async resolveId(id, importer, options) {
if (id.endsWith('.wasm')) {
return {
id,
external: true
};
} else if (id.endsWith('.wasm?cloudflare')) {
const resolution = await this.resolve(id.slice(0, -11), importer, {
skipSelf: true,
...options
});
if (resolution && !resolution.external) {
return `${resolution.id}?cloudflare`;
}
}
return null;
},
load(id) {
if (id.endsWith('.wasm?cloudflare')) {
const name = id.slice(0, -11);
const hash = crypto.createHash('sha1').update(name).digest('hex').slice(0, 16);
fileNames[name] = `${hash}.wasm`;
return `export { default } from './${fileNames[name]}'`;
}
return null;
},
async generateBundle(outputOptions) {
const base = outputOptions.dir || path.dirname(outputOptions.file);
await makeDir(base);
await Promise.all(
Object.keys(fileNames).map(async (name) => {
const output = fileNames[name];
return new Promise((resolve, reject) => {
const read = createReadStream(name);
read.on('error', reject);
const write = createWriteStream(path.join(base, output));
write.on('error', reject);
write.on('finish', resolve);
read.pipe(write);
});
})
);
}
};
}
export default [
{
input: 'src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'es',
sourcemap: true
}
],
external: [
'@resvg/resvg-js',
'base64-arraybuffer',
'opentype.js',
'twemoji',
'twemoji-parser'
],
plugins: [esbuild(), nodeResolve()]
},
{
input: 'src/index.ts',
output: {
file: 'dist/index.d.ts',
format: 'es'
},
plugins: [dts()]
},
{
input: 'src/cloudflare/index.ts',
output: [
{
file: 'cloudflare/index.js',
format: 'es',
sourcemap: true
}
],
external: [
'@resvg/resvg-wasm',
'base64-arraybuffer',
'opentype.js',
'twemoji',
'twemoji-parser'
],
plugins: [wasm(), esbuild(), nodeResolve()]
},
{
input: 'src/cloudflare/index.ts',
output: {
file: 'cloudflare/index.d.ts',
format: 'es'
},
plugins: [dts()]
}
];