uni-helper / unocss-preset-uni

专为 uni-app 打造的 UnoCSS 预设
MIT License
74 stars 6 forks source link

不支持在hbuilderx中使用 #22

Closed qyd159 closed 6 months ago

qyd159 commented 6 months ago

描述问题

unocss/vite不支持在huilderx中使用,hbulderx不支持使用vite.config.mts作为配置

复现

hbuilderx项目根目录下vite配置 vite.config.ts

import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import inject from '@rollup/plugin-inject';
import UnoCSS from 'unocss/vite'

const mpStoragePath = path.resolve(__dirname, './js_sdk/mp-storage/mp-storage');

function join(...args){
    return path.join(__dirname, ...args)
}
export default defineConfig({
  resolve: {
    alias: {
        '@': join(''),
        '~': join(''),
        'socket.io-client':join('node_modules/weapp.socket.io/lib/weapp.socket.io.wx.js'),
        'localStorage': join('js_sdk/mp-storage/mp-storage/index.js')
    }
  },
  build:{
    minify: false
  },
  define:{
    uni: 'uni',
    wx: 'wx'
  },
  plugins: [
    uni(),
    vueJsx({
      // options are passed on to @vue/babel-plugin-jsx
    }),
    UnoCSS(),
    inject({
        localStorage: [mpStoragePath, 'localStorage'],
        'window.localStorage': [mpStoragePath, 'localStorage'],
    }),
  ],
});
X [ERROR] "unocss/vite" resolved to an ESM file. ESM file cannot be loaded by `require`. See https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details. [plugin externalize-deps]
21:44:12.926     node_modules/esbuild/lib/main.js:1374:27:
21:44:12.938       1374 │         let result = await callback({
21:44:12.948            ╵                            ^
21:44:12.958     at file:///C:/software/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:68630:35
21:44:12.969     at requestCallbacks.on-resolve (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:1374:28)
21:44:12.978     at handleRequest (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:732:17)
21:44:12.981     at handleIncomingPacket (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:757:7)
21:44:12.991     at Socket.readFromStdout (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:680:7)
21:44:12.999     at Socket.emit (node:events:517:28)
21:44:13.007     at addChunk (node:internal/streams/readable:368:12)
21:44:13.016     at readableAddChunk (node:internal/streams/readable:341:9)
21:44:13.029     at Readable.push (node:internal/streams/readable:278:10)
21:44:13.037     at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
21:44:13.046   This error came from the "onResolve" callback registered here:
21:44:13.054     node_modules/esbuild/lib/main.js:1293:20:
21:44:13.063       1293 │       let promise = setup({
21:44:13.070            ╵                     ^
21:44:13.079     at setup (file:///C:/software/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:68594:27)
21:44:13.087     at handlePlugins (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:1293:21)
21:44:13.096     at buildOrContextImpl (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:979:5)
21:44:13.103     at Object.buildOrContext (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:788:5)
21:44:13.112     at C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:2215:15
21:44:13.119     at new Promise (<anonymous>)
21:44:13.129     at Object.build (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:2214:25)
21:44:13.136     at build (C:\software\HBuilderX\plugins\uniapp-cli-vite\node_modules\esbuild\lib\main.js:2047:51)
21:44:13.145     at bundleConfigFile (file:///C:/software/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:68553:26)

系统信息

基础环境信息:

基础依赖信息:

使用的包管理器

yarn

核对

Skiyee commented 6 months ago

请用以下使用方式代替

// vite.config.ts
import { defineConfig } from 'vite'

export default async () => {
  const UnoCSS = (await import('unocss/vite')).default

  return defineConfig({
    plugins: [
      UnoCSS()
      //...
    ],
  })
}