@storybook/builder-vite 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86,6 +86,7 @@ export async function generateIframeScriptCode(options: ExtendedOptions) {
86
86
  return addParameters(v, false);
87
87
  }
88
88
  case 'decorateStory':
89
+ case 'applyDecorators':
89
90
  case 'renderToDOM': {
90
91
  return null; // This key is not handled directly in v6 mode.
91
92
  }
@@ -82,6 +82,7 @@ async function generateIframeScriptCode(options) {
82
82
  return addParameters(v, false);
83
83
  }
84
84
  case 'decorateStory':
85
+ case 'applyDecorators':
85
86
  case 'renderToDOM': {
86
87
  return null; // This key is not handled directly in v6 mode.
87
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"codegen-iframe-script.js","sourceRoot":"","sources":["../codegen-iframe-script.ts"],"names":[],"mappings":";;;AAAA,6DAA8E;AAC9E,mEAA8D;AAGvD,KAAK,UAAU,wBAAwB,CAAC,OAAwB;IACrE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACtD,MAAM,mBAAmB,GAAG,aAAa,IAAI,cAAc,SAAS,EAAE,CAAC;IAEvE,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEzD,MAAM,qBAAqB,GAAG,CAAC,KAAe,EAAE,IAAY,EAAE,EAAE,CAC9D,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,IAAA,qCAAgB,EAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE9G,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;IAE9G,0CAA0C;IAC1C,sDAAsD;IACtD,sBAAsB;IACtB,MAAM,IAAI,GAAG;;;iCAGkB,mBAAmB;;;;MAI9C,qBAAqB,CAAC,aAAa,EAAE,QAAQ,CAAC;gCACpB,uCAAkB;qCACb,uCAAkB;;;;;;;;;;;uBAWhC,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmEjG,CAAC,IAAI,EAAE,CAAC;IACX,OAAO,IAAI,CAAC;AACd,CAAC;AAxGD,4DAwGC","sourcesContent":["import { virtualPreviewFile, virtualStoriesFile } from './virtual-file-names';\nimport { transformAbsPath } from './utils/transform-abs-path';\nimport type { ExtendedOptions } from './types';\n\nexport async function generateIframeScriptCode(options: ExtendedOptions) {\n const { presets, frameworkPath, framework } = options;\n const frameworkImportPath = frameworkPath || `@storybook/${framework}`;\n\n const presetEntries = await presets.apply('config', [], options);\n const configEntries = [...presetEntries].filter(Boolean);\n\n const absoluteFilesToImport = (files: string[], name: string) =>\n files.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'${transformAbsPath(el)}'`).join('\\n');\n\n const importArray = (name: string, length: number) => new Array(length).fill(0).map((_, i) => `${name}_${i}`);\n\n // noinspection UnnecessaryLocalVariableJS\n /** @todo Inline variable and remove `noinspection` */\n // language=JavaScript\n const code = `\n // Ensure that the client API is initialized by the framework before any other iframe code\n // is loaded. That way our client-apis can assume the existence of the API+store\n import { configure } from '${frameworkImportPath}';\n\n import * as clientApi from \"@storybook/client-api\";\n import { logger } from '@storybook/client-logger';\n ${absoluteFilesToImport(configEntries, 'config')}\n import * as preview from '${virtualPreviewFile}';\n import { configStories } from '${virtualStoriesFile}';\n\n const {\n addDecorator,\n addParameters,\n addLoader,\n addArgTypesEnhancer,\n addArgsEnhancer,\n setGlobalRender,\n } = clientApi;\n\n const configs = [${importArray('config', configEntries.length).concat('preview.default').join(',')}].filter(Boolean)\n\n configs.forEach(config => {\n Object.keys(config).forEach((key) => {\n const value = config[key];\n switch (key) {\n case 'args': {\n if (typeof clientApi.addArgs !== \"undefined\") {\n return clientApi.addArgs(value);\n } else {\n return logger.warn(\n \"Could not add global args. Please open an issue in storybookjs/builder-vite.\"\n );\n }\n }\n case 'argTypes': {\n if (typeof clientApi.addArgTypes !== \"undefined\") {\n return clientApi.addArgTypes(value);\n } else {\n return logger.warn(\n \"Could not add global argTypes. Please open an issue in storybookjs/builder-vite.\"\n );\n }\n }\n case 'decorators': {\n return value.forEach((decorator) => addDecorator(decorator, false));\n }\n case 'loaders': {\n return value.forEach((loader) => addLoader(loader, false));\n }\n case 'parameters': {\n return addParameters({ ...value }, false);\n }\n case 'argTypesEnhancers': {\n return value.forEach((enhancer) => addArgTypesEnhancer(enhancer));\n }\n case 'argsEnhancers': {\n return value.forEach((enhancer) => addArgsEnhancer(enhancer))\n }\n case 'render': {\n return setGlobalRender(value)\n }\n case 'globals':\n case 'globalTypes': {\n const v = {};\n v[key] = value;\n return addParameters(v, false);\n }\n case 'decorateStory':\n case 'renderToDOM': {\n return null; // This key is not handled directly in v6 mode.\n }\n default: {\n // eslint-disable-next-line prefer-template\n return console.log(key + ' was not supported :( !');\n }\n }\n });\n })\n \n /* TODO: not quite sure what to do with this, to fix HMR\n if (import.meta.hot) {\n import.meta.hot.accept(); \n }\n */\n\n configStories(configure);\n `.trim();\n return code;\n}\n"]}
1
+ {"version":3,"file":"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CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoEjG,CAAC,IAAI,EAAE,CAAC;IACX,OAAO,IAAI,CAAC;AACd,CAAC;AAzGD,4DAyGC","sourcesContent":["import { virtualPreviewFile, virtualStoriesFile } from './virtual-file-names';\nimport { transformAbsPath } from './utils/transform-abs-path';\nimport type { ExtendedOptions } from './types';\n\nexport async function generateIframeScriptCode(options: ExtendedOptions) {\n const { presets, frameworkPath, framework } = options;\n const frameworkImportPath = frameworkPath || `@storybook/${framework}`;\n\n const presetEntries = await presets.apply('config', [], options);\n const configEntries = [...presetEntries].filter(Boolean);\n\n const absoluteFilesToImport = (files: string[], name: string) =>\n files.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'${transformAbsPath(el)}'`).join('\\n');\n\n const importArray = (name: string, length: number) => new Array(length).fill(0).map((_, i) => `${name}_${i}`);\n\n // noinspection UnnecessaryLocalVariableJS\n /** @todo Inline variable and remove `noinspection` */\n // language=JavaScript\n const code = `\n // Ensure that the client API is initialized by the framework before any other iframe code\n // is loaded. That way our client-apis can assume the existence of the API+store\n import { configure } from '${frameworkImportPath}';\n\n import * as clientApi from \"@storybook/client-api\";\n import { logger } from '@storybook/client-logger';\n ${absoluteFilesToImport(configEntries, 'config')}\n import * as preview from '${virtualPreviewFile}';\n import { configStories } from '${virtualStoriesFile}';\n\n const {\n addDecorator,\n addParameters,\n addLoader,\n addArgTypesEnhancer,\n addArgsEnhancer,\n setGlobalRender,\n } = clientApi;\n\n const configs = [${importArray('config', configEntries.length).concat('preview.default').join(',')}].filter(Boolean)\n\n configs.forEach(config => {\n Object.keys(config).forEach((key) => {\n const value = config[key];\n switch (key) {\n case 'args': {\n if (typeof clientApi.addArgs !== \"undefined\") {\n return clientApi.addArgs(value);\n } else {\n return logger.warn(\n \"Could not add global args. Please open an issue in storybookjs/builder-vite.\"\n );\n }\n }\n case 'argTypes': {\n if (typeof clientApi.addArgTypes !== \"undefined\") {\n return clientApi.addArgTypes(value);\n } else {\n return logger.warn(\n \"Could not add global argTypes. Please open an issue in storybookjs/builder-vite.\"\n );\n }\n }\n case 'decorators': {\n return value.forEach((decorator) => addDecorator(decorator, false));\n }\n case 'loaders': {\n return value.forEach((loader) => addLoader(loader, false));\n }\n case 'parameters': {\n return addParameters({ ...value }, false);\n }\n case 'argTypesEnhancers': {\n return value.forEach((enhancer) => addArgTypesEnhancer(enhancer));\n }\n case 'argsEnhancers': {\n return value.forEach((enhancer) => addArgsEnhancer(enhancer))\n }\n case 'render': {\n return setGlobalRender(value)\n }\n case 'globals':\n case 'globalTypes': {\n const v = {};\n v[key] = value;\n return addParameters(v, false);\n }\n case 'decorateStory':\n case 'applyDecorators':\n case 'renderToDOM': {\n return null; // This key is not handled directly in v6 mode.\n }\n default: {\n // eslint-disable-next-line prefer-template\n return console.log(key + ' was not supported :( !');\n }\n }\n });\n })\n \n /* TODO: not quite sure what to do with this, to fix HMR\n if (import.meta.hot) {\n import.meta.hot.accept(); \n }\n */\n\n configStories(configure);\n `.trim();\n return code;\n}\n"]}
@@ -3,5 +3,5 @@ declare type Options = {
3
3
  include?: string | RegExp | (string | RegExp)[];
4
4
  exclude?: string | RegExp | (string | RegExp)[];
5
5
  };
6
- export declare function reactDocgen({ include, exclude }?: Options): Plugin;
6
+ export declare function reactDocgen({ include, exclude, }?: Options): Plugin;
7
7
  export {};
@@ -14,7 +14,7 @@ const defaultHandlers = Object.values(react_docgen_1.handlers).map((handler) =>
14
14
  const defaultResolver = react_docgen_1.resolver.findAllExportedComponentDefinitions;
15
15
  const defaultImporter = react_docgen_1.importers.makeFsImporter();
16
16
  const handlers = [...defaultHandlers, actualNameHandler_1.default];
17
- function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules\/.*/] } = {}) {
17
+ function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules\/.*/, '**/**.stories.tsx'], } = {}) {
18
18
  const cwd = process.cwd();
19
19
  const filter = (0, pluginutils_1.createFilter)(include, exclude);
20
20
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"react-docgen.js","sourceRoot":"","sources":["../../plugins/react-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,qDAAmD;AACnD,+CAKsB;AAEtB,gEAAuC;AAEvC,4FAAoE;AAIpE,oFAAoF;AACpF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAc,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;AAChF,MAAM,eAAe,GAAG,uBAAc,CAAC,mCAAmC,CAAC;AAC3E,MAAM,eAAe,GAAG,wBAAe,CAAC,cAAc,EAAE,CAAC;AACzD,MAAM,QAAQ,GAAG,CAAC,GAAG,eAAe,EAAE,2BAAiB,CAAC,CAAC;AAOzD,SAAgB,WAAW,CAAC,EAAE,OAAO,GAAG,oBAAoB,EAAE,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAc,EAAE;IAC1G,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAA,0BAAY,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE9C,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,MAAM,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;gBAAE,OAAO;YAE7B,IAAI;gBACF,yFAAyF;gBACzF,MAAM,aAAa,GAAG,IAAA,oBAAK,EAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC3F,CAAC;gBACb,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;gBAE/B,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;oBAC7B,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC;oBAC3C,IAAI,UAAU,EAAE;wBACd,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;wBAC3C,CAAC,CAAC,MAAM,CAAC,IAAI,UAAU,iBAAiB,OAAO,EAAE,CAAC,CAAC;qBACpD;gBACH,CAAC,CAAC,CAAC;gBAEH,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;oBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;iBAChD,CAAC;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,oFAAoF;gBACpF,qCAAqC;gBACrC,oBAAoB;aACrB;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AApCD,kCAoCC","sourcesContent":["import path from 'path';\nimport { createFilter } from '@rollup/pluginutils';\nimport {\n parse,\n handlers as docgenHandlers,\n resolver as docgenResolver,\n importers as docgenImporters,\n} from 'react-docgen';\nimport type { DocumentationObject } from 'react-docgen/lib/Documentation';\nimport MagicString from 'magic-string';\nimport type { Plugin } from 'vite';\nimport actualNameHandler from './docgen-handlers/actualNameHandler';\n\ntype DocObj = DocumentationObject & { actualName: string };\n\n// TODO: None of these are able to be overridden, so `default` is aspirational here.\nconst defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);\nconst defaultResolver = docgenResolver.findAllExportedComponentDefinitions;\nconst defaultImporter = docgenImporters.makeFsImporter();\nconst handlers = [...defaultHandlers, actualNameHandler];\n\ntype Options = {\n include?: string | RegExp | (string | RegExp)[];\n exclude?: string | RegExp | (string | RegExp)[];\n};\n\nexport function reactDocgen({ include = /\\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules\\/.*/] }: Options = {}): Plugin {\n const cwd = process.cwd();\n const filter = createFilter(include, exclude);\n\n return {\n name: 'react-docgen',\n enforce: 'pre',\n async transform(src: string, id: string) {\n const relPath = path.relative(cwd, id);\n if (!filter(relPath)) return;\n\n try {\n // Since we're using `findAllExportedComponentDefinitions`, this will always be an array.\n const docgenResults = parse(src, defaultResolver, handlers, { importer: defaultImporter, filename: id }) as\n | DocObj[];\n const s = new MagicString(src);\n\n docgenResults.forEach((info) => {\n const { actualName, ...docgenInfo } = info;\n if (actualName) {\n const docNode = JSON.stringify(docgenInfo);\n s.append(`;${actualName}.__docgenInfo=${docNode}`);\n }\n });\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n } catch (e) {\n // Usually this is just an error from react-docgen that it couldn't find a component\n // Only uncomment for troubleshooting\n // console.error(e);\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"react-docgen.js","sourceRoot":"","sources":["../../plugins/react-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,qDAAmD;AACnD,+CAKsB;AAEtB,gEAAuC;AAEvC,4FAAoE;AAIpE,oFAAoF;AACpF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAc,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;AAChF,MAAM,eAAe,GAAG,uBAAc,CAAC,mCAAmC,CAAC;AAC3E,MAAM,eAAe,GAAG,wBAAe,CAAC,cAAc,EAAE,CAAC;AACzD,MAAM,QAAQ,GAAG,CAAC,GAAG,eAAe,EAAE,2BAAiB,CAAC,CAAC;AAOzD,SAAgB,WAAW,CAAC,EAC1B,OAAO,GAAG,oBAAoB,EAC9B,OAAO,GAAG,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,MACxC,EAAE;IACb,MAAM,GAAG,GAAG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'path';\nimport { createFilter } from '@rollup/pluginutils';\nimport {\n parse,\n handlers as docgenHandlers,\n resolver as docgenResolver,\n importers as docgenImporters,\n} from 'react-docgen';\nimport type { DocumentationObject } from 'react-docgen/lib/Documentation';\nimport MagicString from 'magic-string';\nimport type { Plugin } from 'vite';\nimport actualNameHandler from './docgen-handlers/actualNameHandler';\n\ntype DocObj = DocumentationObject & { actualName: string };\n\n// TODO: None of these are able to be overridden, so `default` is aspirational here.\nconst defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);\nconst defaultResolver = docgenResolver.findAllExportedComponentDefinitions;\nconst defaultImporter = docgenImporters.makeFsImporter();\nconst handlers = [...defaultHandlers, actualNameHandler];\n\ntype Options = {\n include?: string | RegExp | (string | RegExp)[];\n exclude?: string | RegExp | (string | RegExp)[];\n};\n\nexport function reactDocgen({\n include = /\\.(mjs|tsx?|jsx?)$/,\n exclude = [/node_modules\\/.*/, '**/**.stories.tsx'],\n}: Options = {}): Plugin {\n const cwd = process.cwd();\n const filter = createFilter(include, exclude);\n\n return {\n name: 'react-docgen',\n enforce: 'pre',\n async transform(src: string, id: string) {\n const relPath = path.relative(cwd, id);\n if (!filter(relPath)) return;\n\n try {\n // Since we're using `findAllExportedComponentDefinitions`, this will always be an array.\n const docgenResults = parse(src, defaultResolver, handlers, { importer: defaultImporter, filename: id }) as\n | DocObj[];\n const s = new MagicString(src);\n\n docgenResults.forEach((info) => {\n const { actualName, ...docgenInfo } = info;\n if (actualName) {\n const docNode = JSON.stringify(docgenInfo);\n s.append(`;${actualName}.__docgenInfo=${docNode}`);\n }\n });\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n } catch (e) {\n // Usually this is just an error from react-docgen that it couldn't find a component\n // Only uncomment for troubleshooting\n // console.error(e);\n }\n },\n };\n}\n"]}
@@ -31,7 +31,6 @@ const path = __importStar(require("path"));
31
31
  const fs_1 = __importDefault(require("fs"));
32
32
  const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
33
33
  const envs_1 = require("./envs");
34
- const mock_core_js_1 = require("./mock-core-js");
35
34
  const code_generator_plugin_1 = require("./code-generator-plugin");
36
35
  const inject_export_order_plugin_1 = require("./inject-export-order-plugin");
37
36
  const mdx_plugin_1 = require("./plugins/mdx-plugin");
@@ -67,12 +66,10 @@ async function commonConfig(options, _type) {
67
66
  }
68
67
  exports.commonConfig = commonConfig;
69
68
  async function pluginConfig(options, _type) {
70
- var _a, _b;
71
69
  const { framework, presets } = options;
72
70
  const svelteOptions = await presets.apply('svelteOptions', {}, options);
73
71
  const plugins = [
74
72
  (0, code_generator_plugin_1.codeGeneratorPlugin)(options),
75
- (0, mock_core_js_1.mockCoreJs)(),
76
73
  (0, source_loader_plugin_1.sourceLoaderPlugin)(options),
77
74
  (0, mdx_plugin_1.mdxPlugin)(options),
78
75
  (0, no_fouc_1.noFouc)(),
@@ -152,11 +149,11 @@ async function pluginConfig(options, _type) {
152
149
  }
153
150
  throw err;
154
151
  }
152
+ const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');
153
+ const config = { ...loadSvelteConfig(), ...svelteOptions };
155
154
  try {
156
155
  const csfPlugin = require('./svelte/csf-plugin').default;
157
- const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');
158
- const config = loadSvelteConfig();
159
- plugins.push(csfPlugin({ ...config, ...svelteOptions }));
156
+ plugins.push(csfPlugin(config));
160
157
  }
161
158
  catch (err) {
162
159
  // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.
@@ -166,28 +163,27 @@ async function pluginConfig(options, _type) {
166
163
  }
167
164
  }
168
165
  const { svelteDocgen } = await Promise.resolve().then(() => __importStar(require('./plugins/svelte-docgen')));
169
- plugins.push(svelteDocgen(svelteOptions));
166
+ plugins.push(svelteDocgen(config));
170
167
  }
171
168
  if (framework === 'preact') {
172
169
  plugins.push(require('@preact/preset-vite').default());
173
170
  }
174
171
  if (framework === 'react') {
175
- const { reactDocgen, reactDocgenTypescriptOptions } = await presets.apply('typescript', {});
176
- let typescriptPresent;
177
- try {
178
- const pkgJson = readPackageJson();
179
- typescriptPresent = pkgJson && (((_a = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.devDependencies) === null || _a === void 0 ? void 0 : _a.typescript) || ((_b = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.dependencies) === null || _b === void 0 ? void 0 : _b.typescript));
180
- }
181
- catch (e) {
182
- typescriptPresent = false;
183
- }
184
- if (reactDocgen === 'react-docgen-typescript' && typescriptPresent) {
185
- plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript').default(reactDocgenTypescriptOptions));
172
+ const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply('typescript', {});
173
+ if (reactDocgenOption === 'react-docgen-typescript') {
174
+ plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript')({
175
+ ...reactDocgenTypescriptOptions,
176
+ // We *need* this set so that RDT returns default values in the same format as react-docgen
177
+ savePropValueAsString: true,
178
+ }));
186
179
  }
187
- else if (reactDocgen) {
180
+ // Add react-docgen so long as the option is not false
181
+ if (typeof reactDocgenOption === 'string') {
188
182
  const { reactDocgen } = await Promise.resolve().then(() => __importStar(require('./plugins/react-docgen')));
189
183
  // Needs to run before the react plugin, so add to the front
190
- plugins.unshift(reactDocgen());
184
+ plugins.unshift(
185
+ // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files
186
+ reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/ }));
191
187
  }
192
188
  }
193
189
  if (framework === 'glimmerx') {
@@ -1 +1 @@
1
- {"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6C;AAE7C,iCAAuD;AACvD,iDAA4C;AAC5C,mEAA8D;AAC9D,6E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C5G;QAAC,OAAO,CAAC,EAAE;YACV,iBAAiB,GAAG,KAAK,CAAC;SAC3B;QAED,IAAI,WAAW,KAAK,yBAAyB,IAAI,iBAAiB,EAAE;YAClE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,kDAAkD,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC,CAAC;SACjH;aAAM,IAAI,WAAW,EAAE;YACtB,MAAM,EAAE,WAAW,EAAE,GAAG,wDAAa,wBAAwB,GAAC,CAAC;YAC/D,4DAA4D;YAC5D,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;SAChC;KACF;IAED,IAAI,SAAS,KAAK,UAAU,EAAE;QAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA3ID,oCA2IC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport viteReact from '@vitejs/plugin-react';\n\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { mockCoreJs } from './mock-core-js';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './plugins/mdx-plugin';\nimport { noFouc } from './plugins/no-fouc';\nimport { sourceLoaderPlugin } from './source-loader-plugin';\n\nimport type { UserConfig } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport type PluginConfigType = 'build' | 'development';\n\nexport function readPackageJson(): Record<string, any> | false {\n const packageJsonPath = path.resolve('package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n return JSON.parse(jsonContent);\n}\n\n// Vite config that is common to development and production mode\nexport async function commonConfig(\n options: ExtendedOptions,\n _type: PluginConfigType\n): Promise<UserConfig & { configFile: false; root: string }> {\n const { framework } = options;\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve:\n framework === 'vue3'\n ? {\n alias: {\n vue: 'vue/dist/vue.esm-bundler.js',\n },\n }\n : {},\n plugins: await pluginConfig(options, _type),\n };\n}\n\nexport async function pluginConfig(options: ExtendedOptions, _type: PluginConfigType) {\n const { framework, presets } = options;\n const svelteOptions: Record<string, any> = await presets.apply('svelteOptions', {}, options);\n\n const plugins = [\n codeGeneratorPlugin(options),\n mockCoreJs(),\n sourceLoaderPlugin(options),\n mdxPlugin(options),\n noFouc(),\n injectExportOrderPlugin,\n // We need the react plugin here to support MDX.\n viteReact({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\\.([tj])sx?$/]),\n }),\n {\n name: 'vite-plugin-storybook-allow',\n enforce: 'post',\n config(config) {\n // if there is no allow list then Vite allows anything in the root directory\n // if there is an allow list then Vite allows anything in the listed directories\n // add the .storybook directory only if there's an allow list so that we don't end up\n // disallowing the root directory unless it's already disallowed\n if (config?.server?.fs?.allow) {\n config.server.fs.allow.push('.storybook');\n }\n },\n },\n ] as Plugin[];\n if (framework === 'vue' || framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @vitejs/plugin-vue to be installed ' +\n 'when using @storybook/vue or @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n if (framework === 'svelte') {\n try {\n const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;\n\n // We need to create two separate svelte plugins, one for stories, and one for other svelte files\n // because stories.svelte files cannot be hot-module-reloaded.\n // Suggested in: https://github.com/sveltejs/vite-plugin-svelte/issues/321#issuecomment-1113205509\n\n // First, create an array containing user exclude patterns, to combine with ours.\n const userExclude = Array.isArray(svelteOptions?.exclude)\n ? svelteOptions?.exclude\n : svelteOptions?.exclude\n ? [svelteOptions?.exclude]\n : [];\n\n // These are the svelte stories we need to exclude from HMR\n const storyPatterns = ['**/*.story.svelte', '**/*.stories.svelte'];\n // Non-story svelte files\n // Starting in 1.0.0-next.42, svelte.config.js is included by default.\n // We disable that, but allow it to be overridden in svelteOptions\n plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));\n // Svelte stories without HMR\n const storySveltePlugin = sveltePlugin({\n ...svelteOptions,\n exclude: userExclude,\n include: storyPatterns,\n hot: false,\n });\n plugins.push({\n // Starting in 1.0.0-next.43, the plugin function returns an array of plugins. We only want the first one here.\n ...(Array.isArray(storySveltePlugin) ? storySveltePlugin[0] : storySveltePlugin),\n name: 'vite-plugin-svelte-stories',\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @sveltejs/vite-plugin-svelte to be installed' +\n ' when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n\n try {\n const csfPlugin = require('./svelte/csf-plugin').default;\n const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');\n const config = loadSvelteConfig();\n plugins.push(csfPlugin({ ...config, ...svelteOptions }));\n } catch (err) {\n // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.\n // If it's any other kind of error, re-throw.\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n }\n\n const { svelteDocgen } = await import('./plugins/svelte-docgen');\n plugins.push(svelteDocgen(svelteOptions));\n }\n\n if (framework === 'preact') {\n plugins.push(require('@preact/preset-vite').default());\n }\n\n if (framework === 'react') {\n const { reactDocgen, reactDocgenTypescriptOptions } = await presets.apply('typescript', {} as TypescriptConfig);\n\n let typescriptPresent;\n\n try {\n const pkgJson = readPackageJson();\n typescriptPresent = pkgJson && (pkgJson?.devDependencies?.typescript || pkgJson?.dependencies?.typescript);\n } catch (e) {\n typescriptPresent = false;\n }\n\n if (reactDocgen === 'react-docgen-typescript' && typescriptPresent) {\n plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript').default(reactDocgenTypescriptOptions));\n } else if (reactDocgen) {\n const { reactDocgen } = await import('./plugins/react-docgen');\n // Needs to run before the react plugin, so add to the front\n plugins.unshift(reactDocgen());\n }\n }\n\n if (framework === 'glimmerx') {\n const plugin = require('vite-plugin-glimmerx/index.cjs');\n plugins.push(plugin.default());\n }\n\n return plugins;\n}\n"]}
1
+ {"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6C;AAE7C,iCAAuD;AACvD,mEAA8D;AAC9D,6EAAuE;AACvE,qDAAiD;AACjD,+CAA2C;AAC3C,iEAA4D;AAO5D,SAAgB,eAAe;IAC7B,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACrD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;QACnC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,WAAW,GAAG,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC;AARD,0CAQC;AAED,gEAAgE;AACzD,KAAK,UAAU,YAAY,CAChC,OAAwB,EACxB,KAAuB;IAEvB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO;QACL,UAAU,EA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M,EAAE,YAAY,EAAE,GAAG,wDAAa,yBAAyB,GAAC,CAAC;QACjE,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;KACpC;IAED,IAAI,SAAS,KAAK,QAAQ,EAAE;QAC1B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KACxD;IAED,IAAI,SAAS,KAAK,OAAO,EAAE;QACzB,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAC1F,YAAY,EACZ,EAAsB,CACvB,CAAC;QAEF,IAAI,iBAAiB,KAAK,yBAAyB,EAAE;YACnD,OAAO,CAAC,IAAI,CACV,OAAO,CAAC,kDAAkD,CAAC,CAAC;gBAC1D,GAAG,4BAA4B;gBAC/B,2FAA2F;gBAC3F,qBAAqB,EAAE,IAAI;aAC5B,CAAC,CACH,CAAC;SACH;QAED,sDAAsD;QACtD,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACzC,MAAM,EAAE,WAAW,EAAE,GAAG,wDAAa,wBAAwB,GAAC,CAAC;YAC/D,4DAA4D;YAC5D,OAAO,CAAC,OAAO;YACb,sGAAsG;YACtG,WAAW,CAAC,EAAE,OAAO,EAAE,iBAAiB,KAAK,cAAc,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CACxG,CAAC;SACH;KACF;IAED,IAAI,SAAS,KAAK,UAAU,EAAE;QAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAjJD,oCAiJC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport viteReact from '@vitejs/plugin-react';\n\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './plugins/mdx-plugin';\nimport { noFouc } from './plugins/no-fouc';\nimport { sourceLoaderPlugin } from './source-loader-plugin';\n\nimport type { UserConfig } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport type PluginConfigType = 'build' | 'development';\n\nexport function readPackageJson(): Record<string, any> | false {\n const packageJsonPath = path.resolve('package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n return JSON.parse(jsonContent);\n}\n\n// Vite config that is common to development and production mode\nexport async function commonConfig(\n options: ExtendedOptions,\n _type: PluginConfigType\n): Promise<UserConfig & { configFile: false; root: string }> {\n const { framework } = options;\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve:\n framework === 'vue3'\n ? {\n alias: {\n vue: 'vue/dist/vue.esm-bundler.js',\n },\n }\n : {},\n plugins: await pluginConfig(options, _type),\n };\n}\n\nexport async function pluginConfig(options: ExtendedOptions, _type: PluginConfigType) {\n const { framework, presets } = options;\n const svelteOptions: Record<string, any> = await presets.apply('svelteOptions', {}, options);\n\n const plugins = [\n codeGeneratorPlugin(options),\n sourceLoaderPlugin(options),\n mdxPlugin(options),\n noFouc(),\n injectExportOrderPlugin,\n // We need the react plugin here to support MDX.\n viteReact({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\\.([tj])sx?$/]),\n }),\n {\n name: 'vite-plugin-storybook-allow',\n enforce: 'post',\n config(config) {\n // if there is no allow list then Vite allows anything in the root directory\n // if there is an allow list then Vite allows anything in the listed directories\n // add the .storybook directory only if there's an allow list so that we don't end up\n // disallowing the root directory unless it's already disallowed\n if (config?.server?.fs?.allow) {\n config.server.fs.allow.push('.storybook');\n }\n },\n },\n ] as Plugin[];\n if (framework === 'vue' || framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @vitejs/plugin-vue to be installed ' +\n 'when using @storybook/vue or @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n if (framework === 'svelte') {\n try {\n const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;\n\n // We need to create two separate svelte plugins, one for stories, and one for other svelte files\n // because stories.svelte files cannot be hot-module-reloaded.\n // Suggested in: https://github.com/sveltejs/vite-plugin-svelte/issues/321#issuecomment-1113205509\n\n // First, create an array containing user exclude patterns, to combine with ours.\n const userExclude = Array.isArray(svelteOptions?.exclude)\n ? svelteOptions?.exclude\n : svelteOptions?.exclude\n ? [svelteOptions?.exclude]\n : [];\n\n // These are the svelte stories we need to exclude from HMR\n const storyPatterns = ['**/*.story.svelte', '**/*.stories.svelte'];\n // Non-story svelte files\n // Starting in 1.0.0-next.42, svelte.config.js is included by default.\n // We disable that, but allow it to be overridden in svelteOptions\n plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));\n // Svelte stories without HMR\n const storySveltePlugin = sveltePlugin({\n ...svelteOptions,\n exclude: userExclude,\n include: storyPatterns,\n hot: false,\n });\n plugins.push({\n // Starting in 1.0.0-next.43, the plugin function returns an array of plugins. We only want the first one here.\n ...(Array.isArray(storySveltePlugin) ? storySveltePlugin[0] : storySveltePlugin),\n name: 'vite-plugin-svelte-stories',\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @sveltejs/vite-plugin-svelte to be installed' +\n ' when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n\n const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');\n const config = { ...loadSvelteConfig(), ...svelteOptions };\n\n try {\n const csfPlugin = require('./svelte/csf-plugin').default;\n plugins.push(csfPlugin(config));\n } catch (err) {\n // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.\n // If it's any other kind of error, re-throw.\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n }\n\n const { svelteDocgen } = await import('./plugins/svelte-docgen');\n plugins.push(svelteDocgen(config));\n }\n\n if (framework === 'preact') {\n plugins.push(require('@preact/preset-vite').default());\n }\n\n if (framework === 'react') {\n const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(\n 'typescript',\n {} as TypescriptConfig\n );\n\n if (reactDocgenOption === 'react-docgen-typescript') {\n plugins.push(\n require('@joshwooding/vite-plugin-react-docgen-typescript')({\n ...reactDocgenTypescriptOptions,\n // We *need* this set so that RDT returns default values in the same format as react-docgen\n savePropValueAsString: true,\n })\n );\n }\n\n // Add react-docgen so long as the option is not false\n if (typeof reactDocgenOption === 'string') {\n const { reactDocgen } = await import('./plugins/react-docgen');\n // Needs to run before the react plugin, so add to the front\n plugins.unshift(\n // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files\n reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\\.(mjs|tsx?|jsx?)$/ : /\\.(mjs|jsx?)$/ })\n );\n }\n }\n\n if (framework === 'glimmerx') {\n const plugin = require('vite-plugin-glimmerx/index.cjs');\n plugins.push(plugin.default());\n }\n\n return plugins;\n}\n"]}
@@ -12,6 +12,7 @@ async function createViteServer(options, devServer) {
12
12
  ...baseConfig,
13
13
  server: {
14
14
  middlewareMode: true,
15
+ appType: 'custom',
15
16
  hmr: {
16
17
  port,
17
18
  server: devServer,
@@ -1 +1 @@
1
- {"version":3,"file":"vite-server.js","sourceRoot":"","sources":["../vite-server.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,iCAA8C;AAC9C,iDAAiD;AACjD,+CAA6C;AAKtC,KAAK,UAAU,gBAAgB,CAAC,OAAwB,EAAE,SAAiB;IAChF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAElC,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAY,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC9D,MAAM,aAAa,GAAG;QACpB,GAAG,UAAU;QACb,MAAM,EAAE;YACN,cAAc,EAAE,IAAI;YACpB,GAAG,EAAE;gBACH,IAAI;gBACJ,MAAM,EAAE,SAAS;aAClB;YACD,EAAE,EAAE;gBACF,MAAM,EAAE,IAAI;aACb;SACF;QACD,YAAY,EAAE,MAAM,IAAA,8BAAe,EAAC,UAAU,EAAE,OAAO,CAAC;KACzD,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAE7E,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAmB,KAAK,CAAC,CAAC;IAC7D,0EAA0E;IAC1E,MAAM,IAAI,GAAG,IAAA,2BAAoB,EAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAClE,kBAAkB;IAClB,WAAW,CAAC,MAAM,GAAG;QACnB,GAAG,WAAW,CAAC,MAAM;QACrB,GAAG,IAAI;KACR,CAAC;IAEF,OAAO,IAAA,mBAAY,EAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AA/BD,4CA+BC","sourcesContent":["import { createServer } from 'vite';\nimport { stringifyProcessEnvs } from './envs';\nimport { getOptimizeDeps } from './optimizeDeps';\nimport { commonConfig } from './vite-config';\n\nimport type { Server } from 'http';\nimport type { EnvsRaw, ExtendedOptions } from './types';\n\nexport async function createViteServer(options: ExtendedOptions, devServer: Server) {\n const { port, presets } = options;\n\n const baseConfig = await commonConfig(options, 'development');\n const defaultConfig = {\n ...baseConfig,\n server: {\n middlewareMode: true,\n hmr: {\n port,\n server: devServer,\n },\n fs: {\n strict: true,\n },\n },\n optimizeDeps: await getOptimizeDeps(baseConfig, options),\n };\n\n const finalConfig = await presets.apply('viteFinal', defaultConfig, options);\n\n const envsRaw = await presets.apply<Promise<EnvsRaw>>('env');\n // Stringify env variables after getting `envPrefix` from the final config\n const envs = stringifyProcessEnvs(envsRaw, finalConfig.envPrefix);\n // Update `define`\n finalConfig.define = {\n ...finalConfig.define,\n ...envs,\n };\n\n return createServer(finalConfig);\n}\n"]}
1
+ {"version":3,"file":"vite-server.js","sourceRoot":"","sources":["../vite-server.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,iCAA8C;AAC9C,iDAAiD;AACjD,+CAA6C;AAKtC,KAAK,UAAU,gBAAgB,CAAC,OAAwB,EAAE,SAAiB;IAChF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAElC,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAY,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC9D,MAAM,aAAa,GAAG;QACpB,GAAG,UAAU;QACb,MAAM,EAAE;YACN,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,QAAQ;YACjB,GAAG,EAAE;gBACH,IAAI;gBACJ,MAAM,EAAE,SAAS;aAClB;YACD,EAAE,EAAE;gBACF,MAAM,EAAE,IAAI;aACb;SACF;QACD,YAAY,EAAE,MAAM,IAAA,8BAAe,EAAC,UAAU,EAAE,OAAO,CAAC;KACzD,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAE7E,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAmB,KAAK,CAAC,CAAC;IAC7D,0EAA0E;IAC1E,MAAM,IAAI,GAAG,IAAA,2BAAoB,EAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAClE,kBAAkB;IAClB,WAAW,CAAC,MAAM,GAAG;QACnB,GAAG,WAAW,CAAC,MAAM;QACrB,GAAG,IAAI;KACR,CAAC;IAEF,OAAO,IAAA,mBAAY,EAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AAhCD,4CAgCC","sourcesContent":["import { createServer } from 'vite';\nimport { stringifyProcessEnvs } from './envs';\nimport { getOptimizeDeps } from './optimizeDeps';\nimport { commonConfig } from './vite-config';\n\nimport type { Server } from 'http';\nimport type { EnvsRaw, ExtendedOptions } from './types';\n\nexport async function createViteServer(options: ExtendedOptions, devServer: Server) {\n const { port, presets } = options;\n\n const baseConfig = await commonConfig(options, 'development');\n const defaultConfig = {\n ...baseConfig,\n server: {\n middlewareMode: true,\n appType: 'custom',\n hmr: {\n port,\n server: devServer,\n },\n fs: {\n strict: true,\n },\n },\n optimizeDeps: await getOptimizeDeps(baseConfig, options),\n };\n\n const finalConfig = await presets.apply('viteFinal', defaultConfig, options);\n\n const envsRaw = await presets.apply<Promise<EnvsRaw>>('env');\n // Stringify env variables after getting `envPrefix` from the final config\n const envs = stringifyProcessEnvs(envsRaw, finalConfig.envPrefix);\n // Update `define`\n finalConfig.define = {\n ...finalConfig.define,\n ...envs,\n };\n\n return createServer(finalConfig);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A plugin to run and build Storybooks with Vite",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,10 +13,13 @@
13
13
  },
14
14
  "homepage": "https://github.com/storybookjs/builder-vite/#readme",
15
15
  "dependencies": {
16
- "@joshwooding/vite-plugin-react-docgen-typescript": "0.0.4",
16
+ "@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
17
+ "@rollup/pluginutils": "^4.2.1",
18
+ "@storybook/core-common": "^6.4.3",
17
19
  "@storybook/mdx1-csf": "^0.0.4",
20
+ "@storybook/node-logger": "^6.4.3",
18
21
  "@storybook/source-loader": "^6.4.3",
19
- "@vitejs/plugin-react": "^2.0.0-beta.1",
22
+ "@vitejs/plugin-react": "^2.0.0",
20
23
  "ast-types": "^0.14.2",
21
24
  "es-module-lexer": "^0.9.3",
22
25
  "glob": "^7.2.0",
@@ -28,16 +31,14 @@
28
31
  },
29
32
  "devDependencies": {
30
33
  "@storybook/mdx2-csf": "^0.0.3",
34
+ "@sveltejs/vite-plugin-svelte": "^1.0.0",
31
35
  "@types/express": "^4.17.13",
32
36
  "@types/node": "^17.0.23",
33
37
  "vue-docgen-api": "^4.40.0"
34
38
  },
35
39
  "peerDependencies": {
36
- "@storybook/core-common": ">=6.4.3 || >=6.5.0-alpha.0",
37
40
  "@storybook/mdx2-csf": "^0.0.3",
38
- "@storybook/node-logger": ">=6.4.3 || >=6.5.0-alpha.0",
39
- "@storybook/source-loader": ">=6.4.3 || >=6.5.0-alpha.0",
40
- "vite": ">=3.0.0-alpha || >= 3.0.0"
41
+ "vite": ">= 3.0.0"
41
42
  },
42
43
  "peerDependenciesMeta": {
43
44
  "@storybook/mdx2-csf": {
@@ -24,7 +24,10 @@ type Options = {
24
24
  exclude?: string | RegExp | (string | RegExp)[];
25
25
  };
26
26
 
27
- export function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules\/.*/] }: Options = {}): Plugin {
27
+ export function reactDocgen({
28
+ include = /\.(mjs|tsx?|jsx?)$/,
29
+ exclude = [/node_modules\/.*/, '**/**.stories.tsx'],
30
+ }: Options = {}): Plugin {
28
31
  const cwd = process.cwd();
29
32
  const filter = createFilter(include, exclude);
30
33
 
package/vite-config.ts CHANGED
@@ -5,7 +5,6 @@ import { TypescriptConfig } from '@storybook/core-common';
5
5
  import viteReact from '@vitejs/plugin-react';
6
6
 
7
7
  import { allowedEnvPrefix as envPrefix } from './envs';
8
- import { mockCoreJs } from './mock-core-js';
9
8
  import { codeGeneratorPlugin } from './code-generator-plugin';
10
9
  import { injectExportOrderPlugin } from './inject-export-order-plugin';
11
10
  import { mdxPlugin } from './plugins/mdx-plugin';
@@ -58,7 +57,6 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
58
57
 
59
58
  const plugins = [
60
59
  codeGeneratorPlugin(options),
61
- mockCoreJs(),
62
60
  sourceLoaderPlugin(options),
63
61
  mdxPlugin(options),
64
62
  noFouc(),
@@ -143,11 +141,12 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
143
141
  throw err;
144
142
  }
145
143
 
144
+ const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');
145
+ const config = { ...loadSvelteConfig(), ...svelteOptions };
146
+
146
147
  try {
147
148
  const csfPlugin = require('./svelte/csf-plugin').default;
148
- const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');
149
- const config = loadSvelteConfig();
150
- plugins.push(csfPlugin({ ...config, ...svelteOptions }));
149
+ plugins.push(csfPlugin(config));
151
150
  } catch (err) {
152
151
  // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.
153
152
  // If it's any other kind of error, re-throw.
@@ -157,7 +156,7 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
157
156
  }
158
157
 
159
158
  const { svelteDocgen } = await import('./plugins/svelte-docgen');
160
- plugins.push(svelteDocgen(svelteOptions));
159
+ plugins.push(svelteDocgen(config));
161
160
  }
162
161
 
163
162
  if (framework === 'preact') {
@@ -165,23 +164,29 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
165
164
  }
166
165
 
167
166
  if (framework === 'react') {
168
- const { reactDocgen, reactDocgenTypescriptOptions } = await presets.apply('typescript', {} as TypescriptConfig);
169
-
170
- let typescriptPresent;
171
-
172
- try {
173
- const pkgJson = readPackageJson();
174
- typescriptPresent = pkgJson && (pkgJson?.devDependencies?.typescript || pkgJson?.dependencies?.typescript);
175
- } catch (e) {
176
- typescriptPresent = false;
167
+ const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(
168
+ 'typescript',
169
+ {} as TypescriptConfig
170
+ );
171
+
172
+ if (reactDocgenOption === 'react-docgen-typescript') {
173
+ plugins.push(
174
+ require('@joshwooding/vite-plugin-react-docgen-typescript')({
175
+ ...reactDocgenTypescriptOptions,
176
+ // We *need* this set so that RDT returns default values in the same format as react-docgen
177
+ savePropValueAsString: true,
178
+ })
179
+ );
177
180
  }
178
181
 
179
- if (reactDocgen === 'react-docgen-typescript' && typescriptPresent) {
180
- plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript').default(reactDocgenTypescriptOptions));
181
- } else if (reactDocgen) {
182
+ // Add react-docgen so long as the option is not false
183
+ if (typeof reactDocgenOption === 'string') {
182
184
  const { reactDocgen } = await import('./plugins/react-docgen');
183
185
  // Needs to run before the react plugin, so add to the front
184
- plugins.unshift(reactDocgen());
186
+ plugins.unshift(
187
+ // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files
188
+ reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/ })
189
+ );
185
190
  }
186
191
  }
187
192
 
package/vite-server.ts CHANGED
@@ -14,6 +14,7 @@ export async function createViteServer(options: ExtendedOptions, devServer: Serv
14
14
  ...baseConfig,
15
15
  server: {
16
16
  middlewareMode: true,
17
+ appType: 'custom',
17
18
  hmr: {
18
19
  port,
19
20
  server: devServer,
package/mock-core-js.ts DELETED
@@ -1,17 +0,0 @@
1
- export function mockCoreJs() {
2
- return {
3
- name: 'mock-core-js',
4
- resolveId(id: string) {
5
- if (id.includes('node_modules/core-js')) {
6
- return id;
7
- }
8
- return undefined;
9
- },
10
- load(id: string) {
11
- if (id.includes('node_modules/core-js')) {
12
- return '';
13
- }
14
- return undefined;
15
- },
16
- };
17
- }