@aibee/crc-bmap-vite-plugin
v0.0.4
Published
这是一个专门用于解决 Vite 开发环境中 `import.meta.url` 解析错误的插件。
Downloads
13
Keywords
Readme
@aibee/crc-bmap-vite-plugin
这是一个专门用于解决 Vite 开发环境中 import.meta.url 解析错误的插件。
功能说明
在使用 Vite 进行开发时,对于某些依赖包中的 new URL('./path', import.meta.url) 语法,Vite 无法正确解析资源路径,导致资源加载失败。该插件专门针对 @aibee/crc-bmap 包中的这类问题进行修复。
插件会匹配代码中的 new URL("xx", import.meta.url) 模式,并将其路径替换为 Vite 开发服务器可以正确解析的相对路径格式。
安装方式
# 使用 npm
npm install @aibee/crc-bmap-vite-plugin
# 使用 yarn
yarn add @aibee/crc-bmap-vite-plugin
# 使用 pnpm
pnpm install @aibee/crc-bmap-vite-plugin使用方法
// vite.config.js
import { defineConfig } from 'vite';
import { crcBMapDevPlugin } from '@aibee/crc-bmap-vite-plugin/crc-bmap-dev';
export default defineConfig({
plugins: [
crcBMapDevPlugin()
]
});工作原理
- 插件只在开发环境(serve mode)下生效
- 针对
@aibee/crc-bmap包中的文件进行处理 - 查找代码中的
new URL("xx", import.meta.url)表达式 - 将其中的路径替换为相对于 Vite 开发服务器的正确路径
- 确保静态资源可以被正确加载
