mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 02:31:05 +08:00
split the html renderer preview entrypoint into docs & non-docs parts
This commit is contained in:
parent
e437742aa8
commit
c656965f51
@ -26,11 +26,9 @@
|
|||||||
"require": "./dist/index.js",
|
"require": "./dist/index.js",
|
||||||
"import": "./dist/index.mjs"
|
"import": "./dist/index.mjs"
|
||||||
},
|
},
|
||||||
"./preview": {
|
"./preset": "./preset.js",
|
||||||
"types": "./dist/config.d.ts",
|
"./dist/preview.mjs": "./dist/preview.mjs",
|
||||||
"require": "./dist/config.js",
|
"./dist/preview-docs.mjs": "./dist/preview-docs.mjs",
|
||||||
"import": "./dist/config.mjs"
|
|
||||||
},
|
|
||||||
"./package.json": "./package.json"
|
"./package.json": "./package.json"
|
||||||
},
|
},
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -71,7 +69,9 @@
|
|||||||
"bundler": {
|
"bundler": {
|
||||||
"entries": [
|
"entries": [
|
||||||
"./src/index.ts",
|
"./src/index.ts",
|
||||||
"./src/config.ts"
|
"./src/preset.ts",
|
||||||
|
"./src/preview.ts",
|
||||||
|
"./src/preview-docs.ts"
|
||||||
],
|
],
|
||||||
"platform": "browser"
|
"platform": "browser"
|
||||||
},
|
},
|
||||||
|
1
code/renderers/html/preset.js
Normal file
1
code/renderers/html/preset.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./dist/preset');
|
@ -1 +0,0 @@
|
|||||||
export * from './dist/config';
|
|
@ -1,7 +0,0 @@
|
|||||||
import { parameters as docsParams } from './docs/config';
|
|
||||||
import type { Parameters } from './types';
|
|
||||||
|
|
||||||
export const parameters: Parameters = { renderer: 'html', ...docsParams };
|
|
||||||
|
|
||||||
export { decorators, argTypesEnhancers } from './docs/config';
|
|
||||||
export { renderToCanvas, render } from './render';
|
|
23
code/renderers/html/src/preset.ts
Normal file
23
code/renderers/html/src/preset.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
const hasDocs = (presetsList: LoadedPreset[]) => {
|
||||||
|
return presetsList.some((preset: string | { name: string }) => {
|
||||||
|
const presetName = typeof preset === 'string' ? preset : preset.name;
|
||||||
|
return presetName.includes('@storybook/addon-docs');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
|
||||||
|
const { presetsList } = options;
|
||||||
|
if (!presetsList) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
const docsInList = hasDocs(presetsList);
|
||||||
|
const result: string[] = [];
|
||||||
|
|
||||||
|
return result
|
||||||
|
.concat(input)
|
||||||
|
.concat([join(__dirname, 'preview.mjs')])
|
||||||
|
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
|
||||||
|
};
|
2
code/renderers/html/src/preview-docs.ts
Normal file
2
code/renderers/html/src/preview-docs.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export { parameters } from './docs/config';
|
||||||
|
export { decorators, argTypesEnhancers } from './docs/config';
|
5
code/renderers/html/src/preview.ts
Normal file
5
code/renderers/html/src/preview.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import type { Parameters } from './types';
|
||||||
|
|
||||||
|
export const parameters: Parameters = { renderer: 'html' };
|
||||||
|
|
||||||
|
export { renderToCanvas, render } from './render';
|
Loading…
x
Reference in New Issue
Block a user