forked from eva-engine/eva.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.miniprogram.plugin.js
56 lines (50 loc) · 1.34 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 moduleName = '@eva/miniprogram-adapter';
function register(name) {
return [moduleName, name];
}
const adapterArray = {
window: 'windowAlias',
atob: 'atob',
devicePixelRatio: 'devicePixelRatio',
document: 'documentAlias',
Element: 'Element',
Event: 'Event',
EventTarget: 'EventTarget',
HTMLCanvasElement: 'HTMLCanvasElement',
HTMLElement: 'HTMLElement',
HTMLMediaElement: 'HTMLMediaElement',
HTMLVideoElement: 'HTMLVideoElement',
Image: 'Image',
navigator: 'navigator',
Node: 'Node',
requestAnimationFrame: 'requestAnimationFrame',
cancelAnimationFrame: 'cancelAnimationFrame',
screen: 'screen',
XMLHttpRequest: 'XMLHttpRequestAlias',
performance: 'performance',
HTMLImageElement: 'Image',
};
const adapterVars = {};
for (let name in adapterArray) {
adapterVars[name] = register(adapterArray[name]);
}
const plugins = [
inject(adapterVars),
modify({
find: /@eva\/([\w\.\/-]*)/g,
replace: (match, moduleName) => {
console.log(match, moduleName);
if (moduleName.indexOf('/dist/miniprogram') > -1) {
return `@eva/${moduleName}`;
}
return `@eva/${moduleName}/dist/miniprogram`;
},
}),
modify({
find: /pixi\.js/g,
replace: `@eva/miniprogram-pixi`,
}),
];
export default plugins;