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: allow definition of stories in vue files #505

Merged
merged 10 commits into from
Jan 9, 2023
2 changes: 1 addition & 1 deletion packages/builder-vite/code-generator-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
// HMR to update the importFn.
server.watcher.on('add', (path) => {
// TODO maybe use the stories declaration in main
if (/\.stories\.([tj])sx?$/.test(path) || /\.(story|stories).mdx$/.test(path)) {
if (/\.stories\.(?:[tj]sx?|vue)$/.test(path) || /\.(story|stories).mdx$/.test(path)) {
// We need to emit a change event to trigger HMR
server.watcher.emit('change', virtualStoriesFile);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-vite/codegen-importfn-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function toImportFn(stories: string[]) {
const objectEntries = stories.map((file) => {
const ext = path.extname(file);
const relativePath = normalizePath(path.relative(process.cwd(), file));
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx'].includes(ext)) {
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx', '.vue'].includes(ext)) {
logger.warn(`Cannot process ${ext} file with storyStoreV7: ${relativePath}`);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/builder-vite/inject-export-order-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const injectExportOrderPlugin = {
// This should only run after the typescript has been transpiled
enforce: 'post',
async transform(code: string, id: string) {
if (!/\.stories\.([tj])sx?$/.test(id) && !/(stories|story).mdx$/.test(id)) {
if (!/\.stories\.(?:[tj]sx?|vue)$/.test(id) && !/(stories|story).mdx$/.test(id)) {
return;
}
// TODO: Maybe convert `injectExportOrderPlugin` to function that returns object,
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-vite/plugins/vue-docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function vueDocgen(vueVersion: 2 | 3): Plugin {
name: 'vue-docgen',

async transform(src: string, id: string) {
if (/\.(vue)$/.test(id)) {
if (/\.vue$/.test(id) && !/\.stories\.vue$/.test(id)) {
const metaData = await parse(id);
const metaSource = JSON.stringify(metaData);
const s = new MagicString(src);
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-vite/source-loader-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sourceLoaderTransform from '@storybook/source-loader';
import type { ExtendedOptions } from './types';
import MagicString from 'magic-string';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/builder-vite/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
// We need the react plugin here to support MDX.
viteReact({
// Do not treat story files as HMR boundaries, storybook itself needs to handle them.
exclude: [/\.stories\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\.([tj])sx?$/]),
exclude: [/\.stories\.(?:[tj]sx?|vue)$/, /node_modules/].concat(framework === 'react' ? [] : [/\.([tj])sx?$/]),
}),
{
name: 'vite-plugin-storybook-allow',
Expand Down