Browse Source

fix(vite): vite build

suzigang 4 years ago
parent
commit
d16e1fffb1

+ 1 - 0
package.json

@@ -72,6 +72,7 @@
   "devDependencies": {
     "@commitlint/cli": "^10.0.0",
     "@commitlint/config-conventional": "^10.0.0",
+    "@tarojs/taro": "^3.2.10",
     "@types/jest": "^26.0.22",
     "@types/node": "^14.14.31",
     "@vitejs/plugin-legacy": "^1.4.0",

+ 0 - 2
src/packages/__VUE/swiper/index.taro.vue

@@ -14,8 +14,6 @@
 <script lang="ts">
 import Taro from '@tarojs/taro';
 import { createComponent } from '@/packages/utils/create';
-import { useTouch } from './use-touch';
-import { useExpose } from '@/packages/utils/useExpose/index';
 const { create, componentName } = createComponent('swiper');
 // import swiperItem from '@/packages/__VUE/swiperitem/index.vue';
 // console.log(Taro)

+ 4 - 1
src/sites/mobile-taro/vue/config/index.js

@@ -20,6 +20,9 @@ const config = {
     )
   },
   defineConstants: {},
+  runtime: {
+    enableSizeAPIs: true
+  },
   copy: {
     patterns: [],
     options: {}
@@ -65,7 +68,7 @@ const config = {
   }
 };
 
-module.exports = function(merge) {
+module.exports = function (merge) {
   if (process.env.NODE_ENV === 'development') {
     return merge({}, config, require('./dev'));
   }

+ 21 - 5
src/sites/mobile-taro/vue/src/pages/swiper/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="demo">
     <h2>基本用法</h2>
-    <view class="demo-box">
+    <view class="demo-box1" id="test">
       <nut-swiper>
         1111
         <!-- <nut-swiper-item v-for="item in list" :key="item">
@@ -48,10 +48,9 @@
 </template>
 
 <script lang="ts">
-import { reactive, toRefs } from 'vue';
-import Taro from '@tarojs/taro';
-// console.log(Taro)
-// console.log(Taro.createSelectorQuery)
+import { reactive, toRefs, onMounted } from 'vue';
+import Taro, { nextTick, eventCenter, getCurrentInstance } from '@tarojs/taro';
+
 export default {
   props: {},
   setup() {
@@ -71,6 +70,23 @@ export default {
     const change = (index: number) => {
       state.current = index + 1;
     };
+    onMounted(() => {
+      eventCenter.once(
+        (getCurrentInstance() as any).router.onReady,
+        async () => {
+          // const query = Taro.createSelectorQuery()
+          const query = document.querySelector('#test') as any;
+          const res = await query.getBoundingClientRect();
+          console.log(res);
+          // console.log(document.querySelector('#test'))
+          // console.log(query)
+          // query.select('#test').boundingClientRect()
+          // query.exec(res => {
+          // })
+          // console.log('onReady')
+        }
+      );
+    });
     return {
       ...toRefs(state),
       change

+ 1 - 1
vite.config.build.taro.vue.ts

@@ -26,7 +26,7 @@ export default defineConfig({
   build: {
     rollupOptions: {
       // 请确保外部化那些你的库中不需要的依赖
-      external: ['vue', 'vue-router'],
+      external: ['vue', 'vue-router', '@tarojs/taro'],
       output: {
         banner,
         // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量