uni-app unplugin-auto-import/vite插件失效

gblwokeq  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(1109)

问题描述

用vite官方脚手架测试过没有问题,但用uni-preset-vue的vite分支后,发现插件没有效果

复现步骤

  1. 拉取uni-preset-vue最新版vite分支代码
  2. 安装AutoImport
// 页面代码
// 放开注解后正常
<script lang="ts">
// import { ref } from 'vue'
export default {
setup() {
const title = ref('Hello')
return {
title,
}
}
}
</script>
// vite.config.ts
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    uni(),
    AutoImport({
      /* options */
      imports: ['vue'],
      dts: 'src/auto-imports.d.ts',
    }),
  ],
})

预期结果

可以不在代码中显式导入
import { ref } from 'vue'

实际结果

报错

client.ts:22 [vite] connecting...
client.ts:52 [vite] connected.
App.vue:4 App Launch
App.vue:7 App Show
uni-h5.es.js:13934 [Vue warn]: Unhandled error during execution of setup functionundefined 
 at <Index>
at <AsyncComponentWrapper>
at <PageBody>
at <Page>
at <Anonymous>
at <Layout>
at <App>
warnHandler @ uni-h5.es.js:13934
uni-h5.es.js:13934 [Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-nextundefined 
 at <Index>
at <AsyncComponentWrapper>
at <PageBody>
at <Page>
at <Anonymous>
at <Layout>
at <App>
warnHandler @ uni-h5.es.js:13934
index.vue:14 Uncaught (in promise) ReferenceError: ref is not defined
    at setup (index.vue:14)
    at comp.setup (uni-h5.es.js:13955)
    at callWithErrorHandling (vue.runtime.esm.js:7921)
    at setupStatefulComponent (vue.runtime.esm.js:7528)
    at setupComponent (vue.runtime.esm.js:7484)
    at mountComponent (vue.runtime.esm.js:5330)
    at processComponent (vue.runtime.esm.js:5305)
    at patch (vue.runtime.esm.js:4894)
    at ReactiveEffect.componentUpdateFn [as fn] (vue.runtime.esm.js:5519)
    at ReactiveEffect.run (vue.runtime.esm.js:162)
DevTools failed to load source map: Could not load content for chrome-extension://dipiagiiohfljcicegpgffpbnjmgjcnf/js/commons.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://dipiagiiohfljcicegpgffpbnjmgjcnf/js/react.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://dipiagiiohfljcicegpgffpbnjmgjcnf/js/content.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
App.vue:10 App Hide
App.vue:7 App Show

系统信息:

  • 发行平台: [微信小程序、H5平台]
  • 操作系统 win10
  • uni-app版本

"@dcloudio/uni-h5": "^3.0.0-alpha-3021320211119002",
"@dcloudio/uni-mp-weixin": "^3.0.0-alpha-3021320211119002",

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题