diff --git a/README.md b/README.md index d0b6c66..028fa89 100644 --- a/README.md +++ b/README.md @@ -9,22 +9,24 @@ Nuxt Module for Apache EChartsβ„’ -> 🚧 **Work in Progress** +> [!IMPORTANT] > -> Nuxt ECharts is currently in active development and not usable for production yet. +> Nuxt ECharts is currently in active development and based on [experimental ``](https://nuxt.com/docs/api/components/nuxt-island). If you found any issue, design flaw, or have ideas to improve it, please open an [issue](https://github.com/kingyue737/nuxt-echarts/issues) or a [Discussion](https://github.com/kingyue737/nuxt-echarts/discussions). - [✨  Release Notes](/CHANGELOG.md) - +- πŸ€  Online playground (WIP) +- πŸ“–  Documentation (WIP) + -## Features (WIP) +## Features - +- β›° **SSR**: Server-side SVG Rendering with [Nuxt server components](https://nuxt.com/docs/guide/directory-structure/components#server-components) -- β›° **SSR**: experimental server-only component, lightweight client runtime - -- πŸ› οΈ **Configurable**: import only necessary components and charts for smaller bundle size -- 🦾 **Type Strong**: generate ECharts option type based on your config +- ♾️ **Client Hydration**: lazy-loading Full ECharts or [lightweight client runtime](https://echarts.apache.org/handbook/en/how-to/cross-platform/server#using-lightweight-runtime) +- πŸ› οΈ **Configurable**: import only [necessary functionality](https://echarts.apache.org/handbook/en/basics/import#shrinking-bundle-size) for shrinking bundle size +- 🦾 **Type Strong**: auto-import [ECharts option type](https://echarts.apache.org/handbook/en/basics/import#creating-an-option-type-in-typescript) based on your config +- 🌲 **Tree-shaking**: Components and ECharts are only included if you use them ## Quick Setup diff --git a/playground/app.vue b/playground/app.vue index 032ff6a..b8da7db 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -3,6 +3,7 @@ import { registerTheme } from 'echarts/core' import theme from './theme.json' registerTheme('ovilia-green', theme) +// provide(THEME_KEY, 'dark') function random() { return Math.round(300 + Math.random() * 700) / 10 @@ -10,6 +11,7 @@ function random() { function getData(): ECOption { return { + animation: false, dataset: { dimensions: ['Product', '2015', '2016', '2017'], source: [ @@ -57,6 +59,11 @@ const option = shallowRef(getData()) function refreshData() { option.value = getData() } +const initOptions = { height: 400, width: 800 } + +function test() { + console.log('jin') +} diff --git a/src/module.ts b/src/module.ts index 497052a..3ffbbeb 100644 --- a/src/module.ts +++ b/src/module.ts @@ -2,7 +2,7 @@ import { defineNuxtModule, addPlugin, createResolver, - addComponent, + addComponentsDir, addImports, addTemplate, addTypeTemplate, @@ -24,12 +24,12 @@ export default defineNuxtModule({ renderer: 'canvas', }, setup(options, nuxt) { - const resolver = createResolver(import.meta.url) + const { resolve } = createResolver(import.meta.url) // Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack` - addPlugin(resolver.resolve('./runtime/plugin')) - const entry = resolver.resolve('./runtime/components/VChart') - addComponent({ name: 'VChart', filePath: entry }) + addPlugin(resolve('./runtime/plugin')) + addComponentsDir({ path: resolve('runtime/components') }) + nuxt.options.css.push(resolve('./runtime/style.css')) const rendererName = options.renderer === 'canvas' ? 'CanvasRenderer' : 'SVGRenderer' @@ -95,19 +95,14 @@ export default defineNuxtModule({ 'UPDATE_OPTIONS_KEY', 'LOADING_OPTIONS_KEY', ] - injectionKeys.forEach((name) => addImports({ name, from: entry })) + injectionKeys.forEach((name) => + addImports({ name, from: resolve('./runtime/utils/injection') }), + ) if (options.ssr) { //@ts-expect-error We create the `experimental` object if it doesn't exist yet nuxt.options.experimental ||= {} nuxt.options.experimental.componentIslands = true - - addComponent({ - name: 'VChartServer', - filePath: resolver.resolve( - 'runtime/components/VChartServer.server.vue', - ), - }) } }, }) diff --git a/src/runtime/components/VChart.ts b/src/runtime/components/VChart.client.ts similarity index 94% rename from src/runtime/components/VChart.ts rename to src/runtime/components/VChart.client.ts index af9f7f2..9b19931 100644 --- a/src/runtime/components/VChart.ts +++ b/src/runtime/components/VChart.client.ts @@ -12,7 +12,6 @@ import { nextTick, watchEffect, type PropType, - type InjectionKey, } from 'vue' import { init as initChart } from 'echarts/core' import type { @@ -20,11 +19,8 @@ import type { EventTarget, Option, Theme, - ThemeInjection, InitOptions, - InitOptionsInjection, UpdateOptions, - UpdateOptionsInjection, Emits, } from '../types' import { @@ -36,20 +32,18 @@ import { } from '../composables' import { isOn, omitOn } from '../utils/on' import { register, TAG_NAME, type EChartsElement } from '../utils/wc' -import '../style.css' import '#build/echarts.mjs' -const wcRegistered = register() +import { + THEME_KEY, + INIT_OPTIONS_KEY, + UPDATE_OPTIONS_KEY, +} from '../utils/injection' -export const THEME_KEY = 'ecTheme' as unknown as InjectionKey -export const INIT_OPTIONS_KEY = - 'ecInitOptions' as unknown as InjectionKey -export const UPDATE_OPTIONS_KEY = - 'ecUpdateOptions' as unknown as InjectionKey -export { LOADING_OPTIONS_KEY } from '../composables' +const wcRegistered = register() export default defineComponent({ - name: 'echarts', + name: 'VChart', props: { option: Object as PropType