-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathbuild-polyfills.js
60 lines (55 loc) · 1.62 KB
/
build-polyfills.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
const rollup = require('rollup');
// const fs = require('fs');
const path = require('path');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const json = require('rollup-plugin-json');
const license = require('rollup-plugin-license');
async function main() {
await Promise.all([
bundleDependency('process-es6'),
bundleDependency('buffer-es6'),
// bundleDependency('browserify-fs'),
// bundleDependency('crypto-browserify'),
])
// quick and dirty find-replace
// const cryptoPolyfillLoc = path.join(__dirname, '../polyfills/crypto-browserify.js');
// let cryptoPolyfill = fs.readFileSync(cryptoPolyfillLoc, 'utf8');
// cryptoPolyfill = cryptoPolyfill.replace(`import buffer$1 from 'buffer';`, `import * as buffer$1 from 'buffer';`);
// console.log(cryptoPolyfill);
// fs.writeFileSync(cryptoPolyfillLoc, cryptoPolyfill`, 'utf8'`)
}
async function bundleDependency(depName) {
const bundle = await rollup.rollup({
input: depName,
plugins: [
commonjs(),
nodeResolve({
browser: true,
preferBuiltins: true
}),
license({
thirdParty: {
output: path.join(__dirname, '..', 'polyfills', `LICENSE-${depName}.txt`),
includePrivate: true, // Default is false.
encoding: 'utf-8', // Default is utf-8.
}
}),
json(),
],
external: [
'crypto',
'vm',
'events',
'path',
'stream',
'util',
'buffer'
]
});
await bundle.write({
format: 'esm',
file: path.join('polyfills', depName + '.js')
});
}
main();