Cecilxx / echarts-taro3-react

taro3.x-react构建的微信小程序echarts组件,及使用示列
MIT License
84 stars 26 forks source link

包里自带的echarts.js比较旧,有些echarts的新特性不支持,所以我写了个taro插件用来覆盖旧有的包 #35

Open jhxxs opened 2 years ago

jhxxs commented 2 years ago

鉴于echarts-taro3-react的自带的echarts.js比较旧,而且在hooks写法下还会出现报错,所以简单写了个taro插件来覆盖node_module里的文件并替换可能导致错误的地方。

单独做个npm包有点麻烦,所以这里做个记录,希望大佬不要介意,有需要的自取:

  1. 首先去Echarts在线定制页面构建自己需要的echarts.min.js,下载后放到项目的config目录下,我试了使用最新的5.3.2版本正常运行

  2. 在项目的config目录下新建echarts.ts自定义taro插件(保证和自己下载的echarts.min.js在同一目录):

    
    import { IPluginContext } from "@tarojs/service"
    import fs from "fs"
    import path from "path"

export default (ctx: IPluginContext) => { // 接下来使用 ctx 的时候就能获得智能提示了 ctx.onBuildStart(() => { /* echarts-taro3-react使用的echarts文件 / const nodeModuleEchartsPath = path.join( ctx.paths.nodeModulesPath, "/echarts-taro3-react/lib/ec-canvas/echarts.js" ) /* 自己从echarts官网自定义构建的包 / const customBuildEchartsPath = path.resolve(__dirname, "./echarts.min.js") const text = fs.readFileSync(customBuildEchartsPath).toString() // 修复可能出现addEventListener调用报错 const str = text.replace( /(EventListener)((\w{1}),(\w{1}),(\w{1}))/g, (...args) => { const [, f, a, b, c] = args return ${f}?.(${a},${b},${c}) } ) // 覆盖node_module使用的包 fs.writeFileSync(nodeModuleEchartsPath, str) }) }

3. 在`config/index.js`使用插件
```js
 plugins: [ [path.resolve(__dirname, "./plugin/echarts.ts")] ]
laughfacetogithub commented 2 years ago

addEventListener报错是啥原因啊?我这边也是这个报错。还有另一个报错:Cannot read property 'config' of undefined

laughfacetogithub commented 2 years ago

plugins: [ [path.resolve(__dirname, "./plugin/echarts.ts") ]多了一个"[",有时间改一下。

jhxxs commented 2 years ago

plugins: [ [path.resolve(__dirname, "./plugin/echarts.ts") ]多了一个"[",有时间改一下。

已修复

JoshuaFeng5 commented 1 year ago

使用图表的拖拽事件时候,会有报错。你解决过吗 ![Uploading screenshot-20221124-131905.png…]()