2018-11-02 23:51:27 +01:00
|
|
|
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`
|
2018-11-15 06:13:38 +01:00
|
|
|
<html lang="en-US">
|
|
|
|
<head>
|
|
|
|
<title>Firefox Send</title>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta
|
|
|
|
name="viewport"
|
|
|
|
content="width=device-width, initial-scale=1"
|
|
|
|
/>
|
2018-11-20 15:50:59 +01:00
|
|
|
<base href="file:///android_asset/" />
|
2018-11-15 06:13:38 +01:00
|
|
|
<link href="${files['app.css']}" rel="stylesheet" />
|
|
|
|
<script src="${files['android.js']}"></script>
|
|
|
|
</head>
|
|
|
|
<body></body>
|
|
|
|
</html>
|
2018-11-02 23:51:27 +01:00
|
|
|
`
|
|
|
|
.toString()
|
|
|
|
.replace(/\n\s{6}/g, '\n');
|
2018-11-06 20:21:14 +01:00
|
|
|
compilation.assets['android.html'] = {
|
2018-11-02 23:51:27 +01:00
|
|
|
source() {
|
|
|
|
return page;
|
|
|
|
},
|
|
|
|
size() {
|
|
|
|
return page.length;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AndroidIndexPlugin;
|