android_index_plugin.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const path = require('path');
  2. const html = require('choo/html');
  3. const NAME = 'AndroidIndexPlugin';
  4. function chunkFileNames(compilation) {
  5. const names = {};
  6. for (const chunk of compilation.chunks) {
  7. for (const file of chunk.files) {
  8. if (!/\.map$/.test(file)) {
  9. names[`${chunk.name}${path.extname(file)}`] = file;
  10. }
  11. }
  12. }
  13. return names;
  14. }
  15. class AndroidIndexPlugin {
  16. apply(compiler) {
  17. compiler.hooks.emit.tap(NAME, compilation => {
  18. const files = chunkFileNames(compilation);
  19. const page = html`
  20. <html lang="en-US">
  21. <head>
  22. <title>Firefox Send</title>
  23. <meta charset="utf-8" />
  24. <meta
  25. name="viewport"
  26. content="width=device-width, initial-scale=1"
  27. />
  28. <base href="file:///android_asset/" />
  29. <link href="${files['app.css']}" rel="stylesheet" />
  30. <script src="${files['android.js']}"></script>
  31. </head>
  32. <body></body>
  33. </html>
  34. `
  35. .toString()
  36. .replace(/\n\s{6}/g, '\n');
  37. compilation.assets['android.html'] = {
  38. source() {
  39. return page;
  40. },
  41. size() {
  42. return page.length;
  43. }
  44. };
  45. });
  46. }
  47. }
  48. module.exports = AndroidIndexPlugin;