Skip to content

Commit f0d9d7e

Browse files
tobiasdiezIanVS
andauthored
feat: allow definition of stories in vue files (#505)
* feat: allow definition of stories in vue files * Update vite-config.ts * Update inject-export-order-plugin.ts * Update codegen-importfn-script.ts * Update code-generator-plugin.ts * Update packages/builder-vite/vite-config.ts Co-authored-by: Ian VanSchooten <ian.vanschooten@gmail.com> * Update packages/builder-vite/code-generator-plugin.ts Co-authored-by: Ian VanSchooten <ian.vanschooten@gmail.com> * Update packages/builder-vite/inject-export-order-plugin.ts Co-authored-by: Ian VanSchooten <ian.vanschooten@gmail.com> * Update packages/builder-vite/source-loader-plugin.ts Co-authored-by: Ian VanSchooten <ian.vanschooten@gmail.com> * Update packages/builder-vite/plugins/vue-docgen.ts Co-authored-by: Ian VanSchooten <ian.vanschooten@gmail.com> Co-authored-by: Ian VanSchooten <ian.vanschooten@gmail.com>
1 parent 63eacbf commit f0d9d7e

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

packages/builder-vite/code-generator-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
3939
// HMR to update the importFn.
4040
server.watcher.on('add', (path) => {
4141
// TODO maybe use the stories declaration in main
42-
if (/\.stories\.([tj])sx?$/.test(path) || /\.(story|stories).mdx$/.test(path)) {
42+
if (/\.stories\.(?:[tj]sx?|vue)$/.test(path) || /\.(story|stories).mdx$/.test(path)) {
4343
// We need to emit a change event to trigger HMR
4444
server.watcher.emit('change', virtualStoriesFile);
4545
}

packages/builder-vite/codegen-importfn-script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function toImportFn(stories: string[]) {
2929
const objectEntries = stories.map((file) => {
3030
const ext = path.extname(file);
3131
const relativePath = normalizePath(path.relative(process.cwd(), file));
32-
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx'].includes(ext)) {
32+
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx', '.vue'].includes(ext)) {
3333
logger.warn(`Cannot process ${ext} file with storyStoreV7: ${relativePath}`);
3434
}
3535

packages/builder-vite/inject-export-order-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const injectExportOrderPlugin = {
66
// This should only run after the typescript has been transpiled
77
enforce: 'post',
88
async transform(code: string, id: string) {
9-
if (!/\.stories\.([tj])sx?$/.test(id) && !/(stories|story).mdx$/.test(id)) {
9+
if (!/\.stories\.(?:[tj]sx?|vue)$/.test(id) && !/(stories|story).mdx$/.test(id)) {
1010
return;
1111
}
1212
// TODO: Maybe convert `injectExportOrderPlugin` to function that returns object,

packages/builder-vite/plugins/vue-docgen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function vueDocgen(vueVersion: 2 | 3): Plugin {
77
name: 'vue-docgen',
88

99
async transform(src: string, id: string) {
10-
if (/\.(vue)$/.test(id)) {
10+
if (/\.vue$/.test(id) && !/\.stories\.vue$/.test(id)) {
1111
const metaData = await parse(id);
1212
const metaSource = JSON.stringify(metaData);
1313
const s = new MagicString(src);

packages/builder-vite/source-loader-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sourceLoaderTransform from '@storybook/source-loader';
33
import type { ExtendedOptions } from './types';
44
import MagicString from 'magic-string';
55

6-
const storyPattern = /\.stories\.[jt]sx?$/;
6+
const storyPattern = /\.stories\.(?:[jt]sx?|vue)$/;
77
const storySourcePattern = /var __STORY__ = "(.*)"/;
88
const storySourceReplacement = '--STORY_SOURCE_REPLACEMENT--';
99

packages/builder-vite/vite-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
6666
// We need the react plugin here to support MDX.
6767
viteReact({
6868
// Do not treat story files as HMR boundaries, storybook itself needs to handle them.
69-
exclude: [/\.stories\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\.([tj])sx?$/]),
69+
exclude: [/\.stories\.(?:[tj]sx?|vue)$/, /node_modules/].concat(framework === 'react' ? [] : [/\.([tj])sx?$/]),
7070
}),
7171
{
7272
name: 'vite-plugin-storybook-allow',

0 commit comments

Comments
 (0)