-
Notifications
You must be signed in to change notification settings - Fork 9
/
rollup.miniprogram.plugin.js
56 lines (50 loc) · 1.07 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
import inject from "@rollup/plugin-inject";
import modify from "rollup-plugin-modify";
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",
];
const adapterVars = {};
adapterArray.forEach((name) => {
adapterVars[name] = register(name);
});
const regStr = [`"@galacean/engine"`, `'@galacean/engine'`].join("|");
export default [
inject(adapterVars),
modify({
find: new RegExp(regStr, "g"),
replace: (match, moduleName) => {
return `${match.substr(0, match.length - 1)}/dist/miniprogram"`;
},
}),
];