首页 > 解决方案 > 如何将 cdn 与 vite 一起使用(使用 react + antd-mobile)?

问题描述

浏览器报错:

未捕获的类型错误:无法解析模块说明符“antd-mobile”。相对引用必须以“/”、“./”或“../”开头。

我的配置:

import reactRefresh from '@vitejs/plugin-react-refresh'
import {defineConfig} from 'vite'
import cdn from 'vite-plugin-cdn'

// https://vitejs.dev/config/
export default defineConfig({
  base: '',
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      }
    }
  },
  plugins: [
    reactRefresh(),
    cdn({
      modules: [
        {
          name: 'antd-mobile',
          url: 'https://cdnjs.cloudflare.com/ajax/libs/antd-mobile/2.3.4/antd-mobile.min.js'
        }
      ]
    })
  ],
  build: {
    rollupOptions: {
      external: ['antd-mobile'],
    }
  }
})

标签: typescriptantdcdnrollupvite

解决方案


推荐阅读