From 1fec45af43ba5a9a50b467f50174830a3173ff05 Mon Sep 17 00:00:00 2001 From: Yue JIN Date: Sun, 23 Jun 2024 21:56:20 +0800 Subject: [PATCH] feat: add ssr switch for VChart --- src/module.ts | 19 ++++++++++++------- src/types.ts | 12 ++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/module.ts b/src/module.ts index 3dbdec1..8b84d00 100644 --- a/src/module.ts +++ b/src/module.ts @@ -6,6 +6,7 @@ import { addImports, addTemplate, addTypeTemplate, + addComponent, } from '@nuxt/kit' import type { ModuleOptions } from './types' @@ -28,7 +29,17 @@ export default defineNuxtModule({ // Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack` addPlugin(resolve('./runtime/plugin')) - addComponentsDir({ path: resolve('runtime/components') }) + + addComponentsDir({ + path: resolve('runtime/components'), + ignore: ['VChart.server.vue', 'VChart.client.ts'], + }) + addComponent({ + filePath: resolve('./runtime/components/VChart.client.ts'), + name: 'VChart', + mode: options.ssr ? 'all' : 'client', + }) + nuxt.options.css.unshift(resolve('./runtime/style.css')) function join(arr?: string[]) { @@ -124,11 +135,5 @@ export default defineNuxtModule({ ].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 - } }, }) diff --git a/src/types.ts b/src/types.ts index d516096..d33e61b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,22 +14,26 @@ export interface ModuleOptions { renderer?: RendererName | RendererName[] /** - * Register the required charts globally + * Register the required charts on client side + * (imported only if `VChart` is used) */ charts?: ChartName[] /** - * Register the required components globally + * Register the required components on client side + * (imported only if `VChart` is used) */ components?: ComponentName[] /** - * Register the required components globally + * Register the required components on client side + * (imported only if `VChart` is used) */ features?: FeaturesName[] /** - * WIP + * This options indicates if `VChart` should also render on server. + * By default, it only render on client. * * @default false */