mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-31 05:03:21 +08:00
Source-loader: Bypass if file has no exports (#9505)
Source-loader: Bypass if file has no exports
This commit is contained in:
commit
3e52df6b12
@ -0,0 +1,8 @@
|
||||
export default {
|
||||
title: 'Core/Re-export source loader',
|
||||
};
|
||||
|
||||
const Story1 = () => 'story1';
|
||||
const Story2 = () => 'story2';
|
||||
|
||||
export { Story1, Story2 };
|
@ -3,7 +3,16 @@ import { getRidOfUselessFilePrefixes } from './dependencies-lookup/getRidOfUsele
|
||||
|
||||
export function transform(inputSource) {
|
||||
return readStory(this, inputSource)
|
||||
.then(getRidOfUselessFilePrefixes)
|
||||
.then(sourceObject => {
|
||||
// if source-loader had trouble parsing the story exports, return the original story
|
||||
// example is
|
||||
// const myStory = () => xxx
|
||||
// export { myStory }
|
||||
if (!sourceObject.source || sourceObject.source.length === 0) {
|
||||
return { source: inputSource };
|
||||
}
|
||||
return getRidOfUselessFilePrefixes(sourceObject);
|
||||
})
|
||||
.then(
|
||||
({
|
||||
prefix,
|
||||
@ -15,7 +24,8 @@ export function transform(inputSource) {
|
||||
localDependencies,
|
||||
idsToFrameworks,
|
||||
}) => {
|
||||
const preamble = `
|
||||
const preamble = prefix
|
||||
? `
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
// @ts-ignore
|
||||
@ -36,7 +46,8 @@ var __MODULE_DEPENDENCIES__ = ${JSON.stringify(dependencies)};
|
||||
var __LOCAL_DEPENDENCIES__ = ${JSON.stringify(localDependencies)};
|
||||
// @ts-ignore
|
||||
var __IDS_TO_FRAMEWORKS__ = ${JSON.stringify(idsToFrameworks)};
|
||||
`;
|
||||
`
|
||||
: '';
|
||||
return `${preamble}\n${source}`;
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user