forked from mozilla/send
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid_index_plugin.js
50 lines (48 loc) · 1.26 KB
/
android_index_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
const path = require('path');
const html = require('choo/html');
const NAME = 'AndroidIndexPlugin';
function chunkFileNames(compilation) {
const names = {};
for (const chunk of compilation.chunks) {
for (const file of chunk.files) {
if (!/\.map$/.test(file)) {
names[`${chunk.name}${path.extname(file)}`] = file;
}
}
}
return names;
}
class AndroidIndexPlugin {
apply(compiler) {
compiler.hooks.emit.tap(NAME, compilation => {
const files = chunkFileNames(compilation);
const page = html`
<html lang="en-US">
<head>
<title>Send</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<base href="file:///android_asset/" />
<link href="${files['app.css']}" rel="stylesheet" />
<script src="${files['android.js']}"></script>
</head>
<body></body>
</html>
`
.toString()
.replace(/\n\s{6}/g, '\n');
compilation.assets['android.html'] = {
source() {
return page;
},
size() {
return page.length;
}
};
});
}
}
module.exports = AndroidIndexPlugin;