config.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. function bodySnippet(id:string) {
  2. return '<div id="' + id + '"></div>';
  3. }
  4. interface ConfigHtmlHead{
  5. meta?: { [key: string]: string }[],
  6. links?: { [key: string]: string }[],
  7. scripts?: { [key: string]: string }[],
  8. }
  9. interface ConfigHtmlBody{
  10. scripts: { [key: string]: string }[],
  11. snippet: string,
  12. }
  13. export interface ConfigHtml{
  14. head: ConfigHtmlHead,
  15. body: ConfigHtmlBody,
  16. }
  17. export interface ConfigPages{
  18. [key: string]: ConfigPage
  19. }
  20. export interface ConfigWindow{
  21. [key: string ]: unknown
  22. }
  23. export interface ConfigType {
  24. src: string,
  25. build: string,
  26. html: ConfigHtml,
  27. pages: ConfigPages,
  28. window: ConfigWindow,
  29. postcssConfigFile: string,
  30. }
  31. export interface ConfigPage{
  32. staticPage: boolean,
  33. buildExclude: boolean,
  34. title: string,
  35. filename: string,
  36. html: ConfigHtml,
  37. window: ConfigWindow,
  38. render: string,
  39. }
  40. const homePage: ConfigPage = {
  41. staticPage: true,
  42. buildExclude: false,
  43. title: 'Home',
  44. filename: 'index.html',
  45. html: {
  46. head: {},
  47. body: {
  48. scripts: [],
  49. snippet: bodySnippet('page-home'),
  50. }
  51. },
  52. window: {},
  53. render: 'import { renderPage } from \'./js/helpers\'; import { HomePage } from \'./js/pages/HomePage\'; renderPage( \'page-home\', HomePage );',
  54. };
  55. const errorPage: ConfigPage = {
  56. staticPage: true,
  57. buildExclude: false,
  58. title: 'Error',
  59. filename: 'error.html',
  60. html: {
  61. head: {},
  62. body: {
  63. scripts: [],
  64. snippet: bodySnippet('page-error'),
  65. }
  66. },
  67. window: {},
  68. render: 'import { renderPage } from \'./js/helpers\'; import { ErrorPage } from \'./js/pages/ErrorPage\'; renderPage( \'page-error\', ErrorPage );',
  69. };
  70. const pages: { [key: string]: ConfigPage } = {
  71. home: homePage,
  72. error: errorPage,
  73. };
  74. const htmlHead: ConfigHtmlHead = {
  75. meta: [
  76. { charset: 'utf-8' },
  77. { content: 'ie=edge', 'http-equiv': 'x-ua-compatible' },
  78. { name: 'viewport', content: 'width=device-width, initial-scale=1' },
  79. ],
  80. links: [],
  81. scripts: [],
  82. };
  83. const htmlBody: ConfigHtmlBody = {
  84. scripts: [],
  85. snippet: '',
  86. };
  87. const html: ConfigHtml = {
  88. head: htmlHead,
  89. body: htmlBody,
  90. };
  91. export const config : ConfigType = {
  92. src: '',
  93. build: '',
  94. pages,
  95. html,
  96. window: {},
  97. postcssConfigFile: '',
  98. };
  99. export default config;