autoImport.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.initAutoImportOptions = void 0;
  4. const uniPreset = {
  5. from: '@dcloudio/uni-app',
  6. imports: [
  7. // uni-app lifecycle
  8. // App and Page
  9. 'onShow',
  10. 'onHide',
  11. // App
  12. 'onAppShow',
  13. 'onLaunch',
  14. 'onError',
  15. 'onThemeChange',
  16. 'onKeyboardHeightChange',
  17. 'onPageNotFound',
  18. 'onUnhandledRejection',
  19. 'onLastPageBackPress',
  20. 'onExit',
  21. // Page
  22. 'onPageShow',
  23. 'onPageHide',
  24. 'onLoad',
  25. 'onReady',
  26. 'onUnload',
  27. 'onResize',
  28. 'onBackPress',
  29. 'onPageScroll',
  30. 'onTabItemTap',
  31. 'onReachBottom',
  32. 'onPullDownRefresh',
  33. // 辅助
  34. 'renderComponentSlot',
  35. ],
  36. };
  37. const uniH5Preset = {
  38. from: '@dcloudio/uni-h5',
  39. imports: [
  40. 'UniElement',
  41. 'UniElementImpl',
  42. 'UniButtonElement',
  43. 'UniCanvasElement',
  44. 'UniCheckboxElement',
  45. 'UniCheckboxGroupElement',
  46. 'UniEditorElement',
  47. 'UniFormElement',
  48. 'UniIconElement',
  49. 'UniImageElement',
  50. 'UniInputElement',
  51. 'UniLabelElement',
  52. 'UniMovableAreaElement',
  53. 'UniMovableViewElement',
  54. 'UniNavigatorElement',
  55. 'UniPickerViewElement',
  56. 'UniPickerViewColumnElement',
  57. 'UniProgressElement',
  58. 'UniRadioElement',
  59. 'UniRadioGroupElement',
  60. 'UniRichTextElement',
  61. 'UniScrollViewElement',
  62. 'UniSliderElement',
  63. 'UniSwiperElement',
  64. 'UniSwiperItemElement',
  65. 'UniSwitchElement',
  66. 'UniTextElement',
  67. 'UniTextareaElement',
  68. 'UniViewElement',
  69. 'UniListViewElement',
  70. 'UniListItemElement',
  71. 'UniStickySectionElement',
  72. 'UniStickyHeaderElement',
  73. 'UniVideoElement',
  74. 'UniWebViewElement',
  75. 'UniMapElement',
  76. 'UniCoverViewElement',
  77. 'UniCoverImageElement',
  78. 'UniPickerElement',
  79. ],
  80. };
  81. const cloudPreset = {
  82. '@dcloudio/uni-cloud': [['default', 'uniCloud']],
  83. };
  84. const vuePreset = {
  85. from: 'vue',
  86. imports: [
  87. // vue lifecycle
  88. 'onActivated',
  89. 'onBeforeMount',
  90. 'onBeforeUnmount',
  91. 'onBeforeUpdate',
  92. 'onErrorCaptured',
  93. 'onDeactivated',
  94. 'onMounted',
  95. 'onServerPrefetch',
  96. 'onUnmounted',
  97. 'onUpdated',
  98. // setup helpers
  99. 'useAttrs',
  100. 'useSlots',
  101. // reactivity,
  102. 'computed',
  103. 'customRef',
  104. 'isReadonly',
  105. 'isRef',
  106. 'isProxy',
  107. 'isReactive',
  108. 'markRaw',
  109. 'reactive',
  110. 'readonly',
  111. 'ref',
  112. 'shallowReactive',
  113. 'shallowReadonly',
  114. 'shallowRef',
  115. 'triggerRef',
  116. 'toRaw',
  117. 'toRef',
  118. 'toRefs',
  119. 'toValue',
  120. 'unref',
  121. 'watch',
  122. 'watchEffect',
  123. 'watchPostEffect',
  124. 'watchSyncEffect',
  125. // component
  126. 'defineComponent',
  127. 'defineAsyncComponent',
  128. 'getCurrentInstance',
  129. 'h',
  130. 'inject',
  131. 'nextTick',
  132. 'provide',
  133. 'useCssModule',
  134. 'createApp',
  135. // effect scope
  136. 'effectScope',
  137. 'EffectScope',
  138. 'getCurrentScope',
  139. 'onScopeDispose',
  140. // types 全部全局导入
  141. ],
  142. };
  143. function initAutoImportOptions(platform, { imports = [], ...userOptions }) {
  144. const autoImport = [uniPreset, cloudPreset, vuePreset];
  145. if (platform === 'web') {
  146. autoImport.push(uniH5Preset);
  147. }
  148. return {
  149. ...userOptions,
  150. include: [/\.[u]?ts$/, /\.[u]?vue/],
  151. exclude: [/[\\/]\.git[\\/]/],
  152. imports: imports.concat(
  153. // app-android 平台暂不注入其他
  154. platform === 'app-android' ? [] : autoImport),
  155. dts: false,
  156. };
  157. }
  158. exports.initAutoImportOptions = initAutoImportOptions;