options.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { h, reactive, createApp, ref } from 'vue'
  2. import { CompilerOptions } from '@vue/compiler-dom'
  3. export const ssrMode = ref(false)
  4. export const compilerOptions: CompilerOptions = reactive({
  5. mode: 'module',
  6. prefixIdentifiers: false,
  7. optimizeBindings: false,
  8. hoistStatic: false,
  9. cacheHandlers: false,
  10. scopeId: null
  11. })
  12. const App = {
  13. setup() {
  14. return () => {
  15. const isSSR = ssrMode.value
  16. const isModule = compilerOptions.mode === 'module'
  17. const usePrefix =
  18. compilerOptions.prefixIdentifiers || compilerOptions.mode === 'module'
  19. return [
  20. h('h1', `Vue 3 Template Explorer`),
  21. h(
  22. 'a',
  23. {
  24. href: `https://github.com/vuejs/vue-next/tree/${__COMMIT__}`,
  25. target: `_blank`
  26. },
  27. `@${__COMMIT__}`
  28. ),
  29. ' | ',
  30. h(
  31. 'a',
  32. {
  33. href:
  34. 'https://app.netlify.com/sites/vue-next-template-explorer/deploys',
  35. target: `_blank`
  36. },
  37. 'History'
  38. ),
  39. h('div', { id: 'options-wrapper' }, [
  40. h('div', { id: 'options-label' }, 'Options ↘'),
  41. h('ul', { id: 'options' }, [
  42. // mode selection
  43. h('li', { id: 'mode' }, [
  44. h('span', { class: 'label' }, 'Mode: '),
  45. h('input', {
  46. type: 'radio',
  47. id: 'mode-module',
  48. name: 'mode',
  49. checked: isModule,
  50. onChange() {
  51. compilerOptions.mode = 'module'
  52. }
  53. }),
  54. h('label', { for: 'mode-module' }, 'module'),
  55. ' ',
  56. h('input', {
  57. type: 'radio',
  58. id: 'mode-function',
  59. name: 'mode',
  60. checked: !isModule,
  61. onChange() {
  62. compilerOptions.mode = 'function'
  63. }
  64. }),
  65. h('label', { for: 'mode-function' }, 'function')
  66. ]),
  67. // SSR
  68. h('li', [
  69. h('input', {
  70. type: 'checkbox',
  71. id: 'ssr',
  72. name: 'ssr',
  73. checked: ssrMode.value,
  74. onChange(e: Event) {
  75. ssrMode.value = (e.target as HTMLInputElement).checked
  76. }
  77. }),
  78. h('label', { for: 'ssr' }, 'SSR')
  79. ]),
  80. // toggle prefixIdentifiers
  81. h('li', [
  82. h('input', {
  83. type: 'checkbox',
  84. id: 'prefix',
  85. disabled: isModule || isSSR,
  86. checked: usePrefix || isSSR,
  87. onChange(e: Event) {
  88. compilerOptions.prefixIdentifiers =
  89. (e.target as HTMLInputElement).checked || isModule
  90. }
  91. }),
  92. h('label', { for: 'prefix' }, 'prefixIdentifiers')
  93. ]),
  94. // toggle hoistStatic
  95. h('li', [
  96. h('input', {
  97. type: 'checkbox',
  98. id: 'hoist',
  99. checked: compilerOptions.hoistStatic && !isSSR,
  100. disabled: isSSR,
  101. onChange(e: Event) {
  102. compilerOptions.hoistStatic = (e.target as HTMLInputElement).checked
  103. }
  104. }),
  105. h('label', { for: 'hoist' }, 'hoistStatic')
  106. ]),
  107. // toggle cacheHandlers
  108. h('li', [
  109. h('input', {
  110. type: 'checkbox',
  111. id: 'cache',
  112. checked: usePrefix && compilerOptions.cacheHandlers && !isSSR,
  113. disabled: !usePrefix || isSSR,
  114. onChange(e: Event) {
  115. compilerOptions.cacheHandlers = (e.target as HTMLInputElement).checked
  116. }
  117. }),
  118. h('label', { for: 'cache' }, 'cacheHandlers')
  119. ]),
  120. // toggle scopeId
  121. h('li', [
  122. h('input', {
  123. type: 'checkbox',
  124. id: 'scope-id',
  125. disabled: !isModule,
  126. checked: isModule && compilerOptions.scopeId,
  127. onChange(e: Event) {
  128. compilerOptions.scopeId =
  129. isModule && (e.target as HTMLInputElement).checked
  130. ? 'scope-id'
  131. : null
  132. }
  133. }),
  134. h('label', { for: 'scope-id' }, 'scopeId')
  135. ]),
  136. // toggle optimizeBindings
  137. h('li', [
  138. h('input', {
  139. type: 'checkbox',
  140. id: 'optimize-bindings',
  141. disabled: !isModule || isSSR,
  142. checked: isModule && !isSSR && compilerOptions.optimizeBindings,
  143. onChange(e: Event) {
  144. compilerOptions.optimizeBindings = (e.target as HTMLInputElement).checked
  145. }
  146. }),
  147. h('label', { for: 'optimize-bindings' }, 'optimizeBindings')
  148. ])
  149. ])
  150. ])
  151. ]
  152. }
  153. }
  154. }
  155. export function initOptions() {
  156. createApp(App).mount(document.getElementById('header')!)
  157. }