Skip to content

Commit

Permalink
feat: add ssr switch for VChart
Browse files Browse the repository at this point in the history
  • Loading branch information
kingyue737 committed Jun 23, 2024
1 parent 35f1707 commit 1fec45a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
19 changes: 12 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
addImports,
addTemplate,
addTypeTemplate,
addComponent,
} from '@nuxt/kit'

import type { ModuleOptions } from './types'
Expand All @@ -28,7 +29,17 @@ export default defineNuxtModule<ModuleOptions>({

// 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[]) {
Expand Down Expand Up @@ -124,11 +135,5 @@ export default defineNuxtModule<ModuleOptions>({
].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
}
},
})
12 changes: 8 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 1fec45a

Please sign in to comment.