forked from galacean/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.miniprogram.plugin.js
65 lines (58 loc) · 1.32 KB
/
rollup.miniprogram.plugin.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
import inject from "@rollup/plugin-inject";
import modify from "rollup-plugin-modify";
const fs = require("fs");
const path = require("path");
const module = "@galacean/engine-miniprogram-adapter";
function register(name) {
return [module, name];
}
const adapterArray = [
"btoa",
"URL",
"Blob",
"window",
"atob",
"devicePixelRatio",
"document",
"Element",
"Event",
"EventTarget",
"HTMLCanvasElement",
"HTMLElement",
"HTMLMediaElement",
"HTMLVideoElement",
"Image",
"navigator",
"Node",
"requestAnimationFrame",
"cancelAnimationFrame",
"screen",
"XMLHttpRequest",
"performance",
"WebGLRenderingContext",
"WebGL2RenderingContext",
"ImageData",
"location",
"OffscreenCanvas",
"URLSearchParams"
];
const adapterVars = {};
adapterArray.forEach((name) => {
adapterVars[name] = register(name);
});
const packages = fs
.readdirSync(path.join(__dirname, "packages"))
.map((dir) => path.join("packages", dir, `package.json`))
.map((pkgPath) => require(path.join(__dirname, pkgPath)))
.map((pkg) => pkg.name)
.map((name) => `"${name}"`);
const regStr = packages.join("|");
export default [
inject(adapterVars),
modify({
find: new RegExp(regStr, "g"),
replace: (match, moduleName) => {
return `${match.substr(0, match.length - 1)}/dist/miniprogram"`;
}
})
];