-
Notifications
You must be signed in to change notification settings - Fork 109
/
rollup.miniprogram.plugin.js
68 lines (61 loc) · 1.73 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
66
67
68
import inject from 'rollup-plugin-inject';
import modify from 'rollup-plugin-modify';
import fs from 'fs'
import path from 'path'
const packages = fs
.readdirSync(path.resolve(__dirname, 'packages'))
.filter(p => !p.endsWith('.ts') && !p.startsWith('.'));
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]);
}
export const miniprogramPlugins1 = [
modify({
find: /@eva\/([\w\.\/-]*)/g,
replace: (match, moduleName) => {
if(moduleName === 'miniprogram-pixi' || moduleName === 'miniprogram-adapter') {
return `@eva/${moduleName}`;
}
if (moduleName.indexOf('/dist/miniprogram') > -1) {
return `@eva/${moduleName}`;
}
if (packages.indexOf(moduleName) > -1) {
return `@eva/${moduleName}/dist/miniprogram`;
}
return `@eva/${moduleName}`;
},
}),
modify({
find: /pixi\.js/g,
replace: `@eva/miniprogram-pixi`,
})
];
export const miniprogramPlugins2 = [
inject(adapterVars)
]