mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-01 05:05:25 +08:00
Fix csf-plugin to load "pre" & async for perf
This commit is contained in:
parent
6bbe7f3cd8
commit
d0cddf51d3
@ -1,5 +1,5 @@
|
||||
import { createUnplugin } from 'unplugin';
|
||||
import fs from 'fs';
|
||||
import fs from 'fs/promises';
|
||||
import { loadCsf, enrichCsf, formatCsf } from '@storybook/csf-tools';
|
||||
|
||||
export interface CsfPluginOptions {
|
||||
@ -14,11 +14,12 @@ const logger = console;
|
||||
export const unplugin = createUnplugin<CsfPluginOptions>((options) => {
|
||||
return {
|
||||
name: 'unplugin-csf',
|
||||
enforce: 'pre',
|
||||
loadInclude(id) {
|
||||
return STORIES_REGEX.test(id);
|
||||
},
|
||||
load(fname) {
|
||||
const code = fs.readFileSync(fname, 'utf-8');
|
||||
async load(fname) {
|
||||
const code = await fs.readFile(fname, 'utf-8');
|
||||
try {
|
||||
const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse();
|
||||
enrichCsf(csf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user