Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export types also from @nuxtjs/storybook #749

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["composables", "dedupe", "nuxt", "ofetch", "Pinia"]
"cSpell.words": ["composables", "dedupe", "nuxt", "nuxtjs", "ofetch", "Pinia"]
}
46 changes: 46 additions & 0 deletions docs/content/1.getting-started/3.typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: 'TypeScript'
description: 'Guide on how to use TypeScript with the Nuxt module'
---

To use the Nuxt module with TypeScript, ensure that imports typically from `@storybook/*` are now replaced by imports from `@nuxtjs/storybook` (or `@storybook-vue/nuxt` if the Nuxt module is not used). This is needed since the Storybook packages are dependencies of the Nuxt module, and are not directly installed in the project.

The following example demonstrates how to use types when configuring Storybook and for writing stories.

::code-group

```typescript [.storybook/main.ts]
import { StorybookConfig } from '@nuxtjs/storybook' // not from '@storybook/core-common'

export default {
stories: ['../components/**/*.stories.ts'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/vue3',
} as StorybookConfig
```

```typescript [components/Button.stories.ts]
import { Meta, Story } from '@nuxtjs/storybook' // not from '@storybook/vue'
import Button from './Button.vue'

export default {
title: 'Example/Button',
component: Button,
} as Meta

const Template: Story = (args) => ({
components: { Button },
setup() {
return { args }
},
template: '<Button v-bind="args" />',
})

export const Primary = Template.bind({})
Primary.args = {
primary: true,
label: 'Button',
}
```

::
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"example:showcase:build": "pnpm run --filter=./examples/showcase/** build",
"example:showcase:storybook:build": "pnpm run --filter=./examples/showcase/** build-storybook",
"example:showcase:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:showcase:storybook:build --project-token=chpt_a53adf402cb628c",
"build": "pnpm run --recursive --filter=./packages/* --parallel build",
"build": "pnpm run --recursive --filter=./packages/* build",
"package": "cd ./packages/storybook-addon && pnpm pack && cd ../nuxt-module && pnpm pack",
"lint": "pnpm lint:eslint && pnpm lint:prettier",
"lint:eslint": "eslint --max-warnings=0 --report-unused-disable-directives .",
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"type": "module",
"exports": {
".": {
"types": "./dist/types.d.ts",
"types": "./dist/module.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
Expand Down Expand Up @@ -57,7 +57,7 @@
"ufo": "^1.5.3"
},
"devDependencies": {
"@nuxt/module-builder": "0.8.1",
"@nuxt/module-builder": "0.8.3",
"vite": "5.4.0",
"unbuild": "2.0.0"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/nuxt-module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { logger } from './logger'

import { setupStorybook } from './storybook'

export type * from '@storybook-vue/nuxt'

export interface ModuleOptions {
/**
* The route where the Storybook application will be available in development mode.
Expand Down
29 changes: 0 additions & 29 deletions packages/storybook-addon/.storybook/tsconfig.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/storybook-addon/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// Path: src/types.d.ts';
export * from '@storybook/vue3'
export * from './types.d'
10 changes: 0 additions & 10 deletions packages/storybook-addon/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'
import type {
Preview,
StoryFn,
StoryObj,
VueRenderer,
Meta,
DecoratorFunction,
} from '@storybook/vue3'
import type { FrameworkOptions as FrameworkOptionsVue } from '@storybook/vue3-vite'
import type { StorybookConfigVite } from '@storybook/builder-vite'

Expand Down Expand Up @@ -40,5 +32,3 @@ export type StorybookConfig = Omit<
> &
StorybookConfigVite &
StorybookConfigFramework

export { Meta, StoryFn, StoryObj, Preview, VueRenderer, DecoratorFunction }
4 changes: 2 additions & 2 deletions packages/storybook-addon/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "./.storybook/tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"target": "ESNext",
"module": "ESNext",
"types": ["vite/client"],
"skipLibCheck": true,
"skipLibCheck": false,
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true,
"paths": {
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.