@storybook/builder-vite 0.1.30 → 0.1.31

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.
package/README.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  Build your stories with [vite](https://vitejs.dev/) for fast startup times and near-instant HMR.
4
4
 
5
+ # Table of Contents
6
+
7
+ - [Migration from storybook-builder-vite](#project-has-been-renamed)
8
+ - [Installation](#installation)
9
+ - [Usage](#usage)
10
+ - [Customize Vite Config](#customize-vite-config)
11
+ - [Svelte Customization](#svelte-customization)
12
+ - [TypeScript](#typescript)
13
+ - [React Docgen](#react-docgen)
14
+ - [Working Directory](#note-about-working-directory)
15
+ - [How to Start a New Project](#getting-started-with-vite-and-storybook-on-a-new-project)
16
+ - [Known issues](#known-issues)
17
+ - [Contributing](#contributing)
18
+
5
19
  ## Project has been renamed
6
20
 
7
21
  This project has moved from `storybook-builder-vite` to `@storybook/builder-vite` as part of a larger effort to improve Vite support in Storybook. To automatically migrate your existing project, you can run
@@ -16,7 +30,7 @@ To manually migrate:
16
30
  2. Install `@storybook/builder-vite`
17
31
  3. Update your `core.builder` setting in `.storybook/main.js` to `@storybook/builder-vite`.
18
32
 
19
- ### Installation
33
+ ## Installation
20
34
 
21
35
  Requirements:
22
36
 
@@ -41,7 +55,7 @@ pnpm add --save-dev @storybook/builder-vite
41
55
 
42
56
  Note: when using `pnpm`, you may need to enable [shamefully-hoist](https://pnpm.io/npmrc#shamefully-hoist), until https://github.com/storybookjs/builder-vite/issues/55 can be fixed.
43
57
 
44
- ### Usage
58
+ ## Usage
45
59
 
46
60
  In your `main.js` configuration file,
47
61
  set `core: { builder: "@storybook/builder-vite" }`.
@@ -106,13 +120,56 @@ module.exports = {
106
120
  };
107
121
  ```
108
122
 
109
- ## Note about working directory
123
+ ### TypeScript
124
+
125
+ Configure your `.storybook/main.ts` to use TypeScript:
126
+
127
+ ```typescript
128
+ import type { StorybookViteConfig } from '@storybook/builder-vite';
129
+
130
+ const config: StorybookViteConfig = {
131
+ // other storybook options...,
132
+ async viteFinal(config, options) {
133
+ // modify and return config
134
+ },
135
+ };
136
+
137
+ export default config;
138
+ ```
139
+
140
+ Or alternatively, you can use named exports:
141
+
142
+ ```typescript
143
+ import type { ViteFinal } from '@storybook/builder-vite';
144
+
145
+ export const viteFinal: ViteFinal = async (config, options) => {
146
+ // modify and return config
147
+ };
148
+ ```
149
+
150
+ See [Customize Vite config](#customize-vite-config) for details about using `viteFinal`.
151
+
152
+ ### React Docgen
153
+
154
+ Docgen is used in Storybook to populate the props table in docs view, the controls panel, and for several other addons. Docgen is supported in vue and react, and there are two docgen options when using react, `react-docgen` and `react-docgen-typescript`. You can learn more about the pros/cons of each in [this gist](https://gist.github.com/shilman/036313ffa3af52ca986b375d90ea46b0). By default, if we find a `typescript` dependency in your `package.json` file, we will assume you're using typescript and will choose `react-docgen-typescript`. You can change this by setting the `typescript.reactDocgen` option in your `.storybook/main.js` file:
155
+
156
+ ```javascript
157
+ module.exports = {
158
+ typescript: {
159
+ reactDocgen: 'react-docgen`
160
+ }
161
+ }
162
+ ```
163
+
164
+ If you're using TypeScript, we encourage you to experiment and see which option works better for your project.
165
+
166
+ ### Note about working directory
110
167
 
111
168
  The builder will by default enable Vite's [server.fs.strict](https://vitejs.dev/config/#server-fs-strict)
112
169
  option, for increased security. The default project `root` is set to the parent directory of the
113
170
  storybook configuration directory. This can be overridden in viteFinal.
114
171
 
115
- ### Getting started with Vite and Storybook (on a new project)
172
+ ## Getting started with Vite and Storybook (on a new project)
116
173
 
117
174
  See https://vitejs.dev/guide/#scaffolding-your-first-vite-project,
118
175
 
@@ -124,7 +181,7 @@ npx sb init --builder @storybook/builder-vite && npm run storybook
124
181
  ## Known issues
125
182
 
126
183
  - HMR: saving a story file does not hot-module-reload, a full reload happens instead. HMR works correctly when saving component files.
127
- - Prebundling: Vite restarts if it detects new dependencies which it did not know about and needs to pre-bundle. This breaks within storybook, with confusing error messages. If you see a message in your terminal like `[vite] new dependencies found:`, please add those dependencies to your `optimizeDeps.include` in `viteFinal`. E.g. `config.optimizeDeps.include = [...(config.optimizeDeps?.include ?? []), "storybook-dark-mode"],`. Vite 2.9.0 may improve this behavior.
184
+ - Prebundling: Vite restarts if it detects new dependencies which it did not know about and needs to pre-bundle. This breaks within storybook, with confusing error messages. If you see a message in your terminal like `[vite] new dependencies found:`, please add those dependencies to your `optimizeDeps.include` in `viteFinal`. E.g. `config.optimizeDeps.include = [...(config.optimizeDeps?.include ?? []), "storybook-dark-mode"],`. Vite 2.9.0+ may improve this behavior.
128
185
 
129
186
  ## Contributing
130
187
 
@@ -46,6 +46,7 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
46
46
  config.build = {};
47
47
  }
48
48
  config.build.rollupOptions = {
49
+ ...config.build.rollupOptions,
49
50
  input: iframePath,
50
51
  };
51
52
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -62,6 +66,7 @@ function codeGeneratorPlugin(options) {
62
66
  config.build = {};
63
67
  }
64
68
  config.build.rollupOptions = {
69
+ ...config.build.rollupOptions,
65
70
  input: iframePath,
66
71
  };
67
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"code-generator-plugin.js","sourceRoot":"","sources":["../code-generator-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,mEAA8D;A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E,CAAC;aACjC;YAED,IAAI,EAAE,KAAK,uCAAkB,IAAI,CAAC,YAAY,EAAE;gBAC9C,OAAO,IAAA,0CAAwB,EAAC,OAAO,CAAC,CAAC;aAC1C;YAED,IAAI,EAAE,KAAK,kCAAa,EAAE;gBACxB,IAAI,YAAY,EAAE;oBAChB,OAAO,IAAA,6DAA8B,EAAC,OAAO,CAAC,CAAC;iBAChD;qBAAM;oBACL,OAAO,IAAA,gDAAwB,EAAC,OAAO,CAAC,CAAC;iBAC1C;aACF;YAED,IAAI,EAAE,KAAK,QAAQ,EAAE;gBACnB,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC;aACxF;QACH,CAAC;QACD,KAAK,CAAC,kBAAkB,CAAC,IAAI,EAAE,GAAG;YAChC,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE;gBAC/B,OAAO;aACR;YACD,OAAO,IAAA,2CAAmB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC;AACJ,CAAC;AApGD,kDAoGC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { transformIframeHtml } from './transform-iframe-html';\nimport { generateIframeScriptCode } from './codegen-iframe-script';\nimport { generateModernIframeScriptCode } from './codegen-modern-iframe-script';\nimport { generateImportFnScriptCode } from './codegen-importfn-script';\nimport { generateVirtualStoryEntryCode, generatePreviewEntryCode } from './codegen-entries';\nimport { generateAddonSetupCode } from './codegen-set-addon-channel';\n\nimport type { Plugin } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nimport { virtualAddonSetupFile, virtualFileId, virtualPreviewFile, virtualStoriesFile } from './virtual-file-names';\n\nexport function codeGeneratorPlugin(options: ExtendedOptions): Plugin {\n const iframePath = path.resolve(__dirname, '..', 'input', 'iframe.html');\n let iframeId: string;\n let projRoot: string;\n\n // noinspection JSUnusedGlobalSymbols\n return {\n name: 'storybook-vite-code-generator-plugin',\n enforce: 'pre',\n configureServer(server) {\n // invalidate the whole vite-app.js script on every file change.\n // (this might be a little too aggressive?)\n server.watcher.on('change', (_e) => {\n const { moduleGraph } = server;\n const appModule = moduleGraph.getModuleById(virtualFileId);\n if (appModule) {\n server.moduleGraph.invalidateModule(appModule);\n }\n const storiesModule = moduleGraph.getModuleById(virtualStoriesFile);\n if (storiesModule) {\n server.moduleGraph.invalidateModule(storiesModule);\n }\n });\n },\n config(config, { command }) {\n // If we are building the static distribution, add iframe.html as an entry.\n // In development mode, it's not an entry - instead, we use an express middleware\n // to serve iframe.html. The reason is that Vite's dev server (at the time of writing)\n // does not support virtual files as entry points.\n if (command === 'build') {\n if (!config.build) {\n config.build = {};\n }\n config.build.rollupOptions = {\n input: iframePath,\n };\n }\n },\n configResolved(config) {\n projRoot = config.root;\n iframeId = `${config.root}/iframe.html`;\n },\n resolveId(source) {\n if (source === virtualFileId) {\n return virtualFileId;\n } else if (source === iframePath) {\n return iframeId;\n } else if (source === virtualStoriesFile) {\n return virtualStoriesFile;\n } else if (source === virtualPreviewFile) {\n return virtualPreviewFile;\n } else if (source === virtualAddonSetupFile) {\n return virtualAddonSetupFile;\n // Avoid error in react < 18 projects\n } else if (source === 'react-dom/client') {\n try {\n return require.resolve('react-dom/client', { paths: [projRoot] });\n } catch (e) {\n // This is not a react 18 project, need to stub out to avoid error\n return path.resolve(__dirname, '..', 'input', 'react-dom-client-placeholder.js');\n }\n }\n },\n async load(id) {\n const storyStoreV7 = options.features?.storyStoreV7;\n if (id === virtualStoriesFile) {\n if (storyStoreV7) {\n return generateImportFnScriptCode(options);\n } else {\n return generateVirtualStoryEntryCode(options);\n }\n }\n\n if (id === virtualAddonSetupFile) {\n return generateAddonSetupCode();\n }\n\n if (id === virtualPreviewFile && !storyStoreV7) {\n return generatePreviewEntryCode(options);\n }\n\n if (id === virtualFileId) {\n if (storyStoreV7) {\n return generateModernIframeScriptCode(options);\n } else {\n return generateIframeScriptCode(options);\n }\n }\n\n if (id === iframeId) {\n return fs.readFileSync(path.resolve(__dirname, '..', 'input', 'iframe.html'), 'utf-8');\n }\n },\n async transformIndexHtml(html, ctx) {\n if (ctx.path !== '/iframe.html') {\n return;\n }\n return transformIframeHtml(html, options);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"code-generator-plugin.js","sourceRoot":"","sources":["../code-generator-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,mEAA8D;AAC9D,mEAAmE;AACnE,iFAAgF;AAChF,uEAAuE;AACvE,uDAA4F;AAC5F,2EAAqE;AAKrE,6DAAoH;AAEpH,SAAgB,mBAAmB,CAAC,OAAwB;IAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IACzE,IAAI,QAAgB,CAAC;IACrB,IAAI,QAAgB,CAAC;IAErB,qCAAqC;IACrC,OAAO;QACL,IAAI,EAAE,sCAAsC;QAC5C,OAAO,EAAE,KAAK;QACd,eAAe,CAAC,MAAM;YACpB,gEAAgE;YAChE,2CAA2C;YAC3C,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE;gBACjC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;gBAC/B,MAAM,SAAS,GAAG,WAAW,CAAC,aAAa,CAAC,kCAAa,CAAC,CAAC;gBAC3D,IAAI,SAAS,EAAE;oBACb,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;iBAChD;gBACD,MAAM,aAAa,GAAG,WAAW,CAAC,aAAa,CAAC,uCAAkB,CAAC,CAAC;gBACpE,IAAI,aAAa,EAAE;oBACjB,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;iBACpD;YACH,CA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AC,CAAC;iBAClF;aACF;QACH,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE;;YACX,MAAM,YAAY,GAAG,MAAA,OAAO,CAAC,QAAQ,0CAAE,YAAY,CAAC;YACpD,IAAI,EAAE,KAAK,uCAAkB,EAAE;gBAC7B,IAAI,YAAY,EAAE;oBAChB,OAAO,IAAA,oDAA0B,EAAC,OAAO,CAAC,CAAC;iBAC5C;qBAAM;oBACL,OAAO,IAAA,+CAA6B,EAAC,OAAO,CAAC,CAAC;iBAC/C;aACF;YAED,IAAI,EAAE,KAAK,0CAAqB,EAAE;gBAChC,OAAO,IAAA,kDAAsB,GAAE,CAAC;aACjC;YAED,IAAI,EAAE,KAAK,uCAAkB,IAAI,CAAC,YAAY,EAAE;gBAC9C,OAAO,IAAA,0CAAwB,EAAC,OAAO,CAAC,CAAC;aAC1C;YAED,IAAI,EAAE,KAAK,kCAAa,EAAE;gBACxB,IAAI,YAAY,EAAE;oBAChB,OAAO,IAAA,6DAA8B,EAAC,OAAO,CAAC,CAAC;iBAChD;qBAAM;oBACL,OAAO,IAAA,gDAAwB,EAAC,OAAO,CAAC,CAAC;iBAC1C;aACF;YAED,IAAI,EAAE,KAAK,QAAQ,EAAE;gBACnB,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC;aACxF;QACH,CAAC;QACD,KAAK,CAAC,kBAAkB,CAAC,IAAI,EAAE,GAAG;YAChC,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE;gBAC/B,OAAO;aACR;YACD,OAAO,IAAA,2CAAmB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC;AACJ,CAAC;AArGD,kDAqGC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { transformIframeHtml } from './transform-iframe-html';\nimport { generateIframeScriptCode } from './codegen-iframe-script';\nimport { generateModernIframeScriptCode } from './codegen-modern-iframe-script';\nimport { generateImportFnScriptCode } from './codegen-importfn-script';\nimport { generateVirtualStoryEntryCode, generatePreviewEntryCode } from './codegen-entries';\nimport { generateAddonSetupCode } from './codegen-set-addon-channel';\n\nimport type { Plugin } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nimport { virtualAddonSetupFile, virtualFileId, virtualPreviewFile, virtualStoriesFile } from './virtual-file-names';\n\nexport function codeGeneratorPlugin(options: ExtendedOptions): Plugin {\n const iframePath = path.resolve(__dirname, '..', 'input', 'iframe.html');\n let iframeId: string;\n let projRoot: string;\n\n // noinspection JSUnusedGlobalSymbols\n return {\n name: 'storybook-vite-code-generator-plugin',\n enforce: 'pre',\n configureServer(server) {\n // invalidate the whole vite-app.js script on every file change.\n // (this might be a little too aggressive?)\n server.watcher.on('change', (_e) => {\n const { moduleGraph } = server;\n const appModule = moduleGraph.getModuleById(virtualFileId);\n if (appModule) {\n server.moduleGraph.invalidateModule(appModule);\n }\n const storiesModule = moduleGraph.getModuleById(virtualStoriesFile);\n if (storiesModule) {\n server.moduleGraph.invalidateModule(storiesModule);\n }\n });\n },\n config(config, { command }) {\n // If we are building the static distribution, add iframe.html as an entry.\n // In development mode, it's not an entry - instead, we use an express middleware\n // to serve iframe.html. The reason is that Vite's dev server (at the time of writing)\n // does not support virtual files as entry points.\n if (command === 'build') {\n if (!config.build) {\n config.build = {};\n }\n config.build.rollupOptions = {\n ...config.build.rollupOptions,\n input: iframePath,\n };\n }\n },\n configResolved(config) {\n projRoot = config.root;\n iframeId = `${config.root}/iframe.html`;\n },\n resolveId(source) {\n if (source === virtualFileId) {\n return virtualFileId;\n } else if (source === iframePath) {\n return iframeId;\n } else if (source === virtualStoriesFile) {\n return virtualStoriesFile;\n } else if (source === virtualPreviewFile) {\n return virtualPreviewFile;\n } else if (source === virtualAddonSetupFile) {\n return virtualAddonSetupFile;\n // Avoid error in react < 18 projects\n } else if (source === 'react-dom/client') {\n try {\n return require.resolve('react-dom/client', { paths: [projRoot] });\n } catch (e) {\n // This is not a react 18 project, need to stub out to avoid error\n return path.resolve(__dirname, '..', 'input', 'react-dom-client-placeholder.js');\n }\n }\n },\n async load(id) {\n const storyStoreV7 = options.features?.storyStoreV7;\n if (id === virtualStoriesFile) {\n if (storyStoreV7) {\n return generateImportFnScriptCode(options);\n } else {\n return generateVirtualStoryEntryCode(options);\n }\n }\n\n if (id === virtualAddonSetupFile) {\n return generateAddonSetupCode();\n }\n\n if (id === virtualPreviewFile && !storyStoreV7) {\n return generatePreviewEntryCode(options);\n }\n\n if (id === virtualFileId) {\n if (storyStoreV7) {\n return generateModernIframeScriptCode(options);\n } else {\n return generateIframeScriptCode(options);\n }\n }\n\n if (id === iframeId) {\n return fs.readFileSync(path.resolve(__dirname, '..', 'input', 'iframe.html'), 'utf-8');\n }\n },\n async transformIndexHtml(html, ctx) {\n if (ctx.path !== '/iframe.html') {\n return;\n }\n return transformIframeHtml(html, options);\n },\n };\n}\n"]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"codegen-importfn-script.js","sourceRoot":"","sources":["../codegen-importfn-script.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+BAAqC;AAGrC,iDAA6C;AAE7C;;GAEG;AAEH;;;;GAIG;AACH,SAAS,YAAY,CAAC,YAAoB;IACxC,OAAO,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,EAAE,CAAC;AAC7E,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,UAAU,CAAC,OAAiB;IACzC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACzC,OAAO,MAAM,YAAY,CAAC,IAAA,oBAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,+BAA+B,IAAI,IAAI,CAAC;IACtH,CAAC,CAAC,CAAC;IAEH,OAAO;;QAED,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;;;;;;GAM9B,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,0BAA0B,CAAC,OAAgB;IAC/D,qEAAqE;IACrE,MAAM,OAAO,GAAG,MAAM,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAC;IAE3C,oGAAoG;IACpG,OAAO,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC;AAND,gEAMC","sourcesContent":["import * as path from 'path';\nimport { normalizePath } from 'vite';\nimport type { Options } from '@storybook/core-common';\n\nimport { listStories } from './list-stories';\n\n/**\n * This file is largely based on https://github.com/storybookjs/storybook/blob/d1195cbd0c61687f1720fefdb772e2f490a46584/lib/core-common/src/utils/to-importFn.ts\n */\n\n/**\n * Paths get passed either with no leading './' - e.g. `src/Foo.stories.js`,\n * or with a leading `../` (etc), e.g. `../src/Foo.stories.js`.\n * We want to deal in importPaths relative to the working dir, so we normalize\n */\nfunction toImportPath(relativePath: string) {\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`;\n}\n\n/**\n * This function takes an array of stories and creates a mapping between the stories' relative paths\n * to the working directory and their dynamic imports. The import is done in an asynchronous function\n * to delay loading. It then creates a function, `importFn(path)`, which resolves a path to an import\n * function and this is called by Storybook to fetch a story dynamically when needed.\n * @param stories An array of absolute story paths.\n */\nasync function toImportFn(stories: string[]) {\n const objectEntries = stories.map((file) => {\n return ` '${toImportPath(normalizePath(path.relative(process.cwd(), file)))}': async () => import('/@fs/${file}')`;\n });\n\n return `\n const importers = {\n ${objectEntries.join(',\\n')}\n };\n\n export async function importFn(path) {\n return importers[path]();\n }\n `;\n}\n\nexport async function generateImportFnScriptCode(options: Options) {\n // First we need to get an array of stories and their absolute paths.\n const stories = await listStories(options);\n\n // We can then call toImportFn to create a function that can be used to load each story dynamically.\n return (await toImportFn(stories)).trim();\n}\n"]}
1
+ {"version":3,"file":"codegen-importfn-script.js","sourceRoot":"","sources":["../codegen-importfn-script.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+BAAqC;AAGrC,iDAA6C;AAE7C;;GAEG;AAEH;;;;GAIG;AACH,SAAS,YAAY,CAAC,YAAoB;IACxC,OAAO,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,EAAE,CAAC;AAC7E,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,UAAU,CAAC,OAAiB;IACzC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACzC,OAAO,MAAM,YAAY,CAAC,IAAA,oBAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,+BAA+B,IAAI,IAAI,CAAC;IACtH,CAAC,CAAC,CAAC;IAEH,OAAO;;QAED,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;;;;;;GAM9B,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,0BAA0B,CAAC,OAAgB;IAC/D,qEAAqE;IACrE,MAAM,OAAO,GAAG,MAAM,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAC;IAE3C,oGAAoG;IACpG,OAAO,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC;AAND,gEAMC","sourcesContent":["import * as path from 'path';\nimport { normalizePath } from 'vite';\nimport type { Options } from '@storybook/core-common';\n\nimport { listStories } from './list-stories';\n\n/**\n * This file is largely based on https://github.com/storybookjs/storybook/blob/d1195cbd0c61687f1720fefdb772e2f490a46584/lib/core-common/src/utils/to-importFn.ts\n */\n\n/**\n * Paths get passed either with no leading './' - e.g. `src/Foo.stories.js`,\n * or with a leading `../` (etc), e.g. `../src/Foo.stories.js`.\n * We want to deal in importPaths relative to the working dir, so we normalize\n */\nfunction toImportPath(relativePath: string) {\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`;\n}\n\n/**\n * This function takes an array of stories and creates a mapping between the stories' relative paths\n * to the working directory and their dynamic imports. The import is done in an asynchronous function\n * to delay loading. It then creates a function, `importFn(path)`, which resolves a path to an import\n * function and this is called by Storybook to fetch a story dynamically when needed.\n * @param stories An array of absolute story paths.\n */\nasync function toImportFn(stories: string[]) {\n const objectEntries = stories.map((file) => {\n return ` '${toImportPath(normalizePath(path.relative(process.cwd(), file)))}': async () => import('/@fs/${file}')`;\n });\n\n return `\n const importers = {\n ${objectEntries.join(',\\n')}\n };\n\n export async function importFn(path) {\n return importers[path]();\n }\n `;\n}\n\nexport async function generateImportFnScriptCode(options: Options) {\n // First we need to get an array of stories and their absolute paths.\n const stories = await listStories(options);\n\n // We can then call toImportFn to create a function that can be used to load each story dynamically.\n return (await toImportFn(stories)).trim();\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- import type { Builder } from '@storybook/core-common';
2
- import type { UserConfig } from 'vite';
1
+ import type { Builder, StorybookConfig } from '@storybook/core-common';
2
+ import type { InlineConfig, UserConfig } from 'vite';
3
3
  export interface ViteStats {
4
4
  }
5
5
  export declare type ViteBuilder = Builder<UserConfig, ViteStats>;
6
+ export declare type ViteFinal = (config: InlineConfig, options: StorybookConfig) => InlineConfig | Promise<InlineConfig>;
7
+ export declare type StorybookViteConfig = StorybookConfig & {
8
+ viteFinal: ViteFinal;
9
+ };
6
10
  export declare const start: ViteBuilder['start'];
7
11
  export declare const build: ViteBuilder['build'];
8
12
  export declare const corePresets: never[];
package/dist/index.js CHANGED
@@ -2,7 +2,11 @@
2
2
  // noinspection JSUnusedGlobalSymbols
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA,qCAAqC;;;;;;;;;;;;;;;;;;;;;;AAErC,uCAAyB;AACzB,2CAA6B;AAC7B,mEAA8D;AAC9D,+CAAiD;AACjD,mCAA6C;AAW7C,SAAS,gBAAgB,CAAC,OAAwB,EAAE,MAAqB;IACvE,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,EAAE;YAC3C,IAAI,EAAE,CAAC;YACP,OAAO;SACR;QAED,yIAAyI;QACzI,2CAA2C;QAC3C,IAAI,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE;YACzC,IAAI,EAAE,CAAC;YACP,OAAO;SACR;Q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I,CAAC,6BAA6B,CAAC,CAAC;SAC7C;QAED,MAAM,CAAC,CAAC;IACV,CAAC;IAED,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,EAAe;QACtB,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC,CAAC;AA5BW,QAAA,KAAK,SA4BhB;AAEK,MAAM,KAAK,GAAyB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IAC/D,OAAO,IAAA,aAAS,EAAC,OAA0B,CAAC,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB;AAEW,QAAA,WAAW,GAAG,EAAE,CAAC;AACjB,QAAA,cAAc,GAAG,EAAE,CAAC","sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { transformIframeHtml } from './transform-iframe-html';\nimport { createViteServer } from './vite-server';\nimport { build as viteBuild } from './build';\n\nimport type { Builder } from '@storybook/core-common';\nimport type { RequestHandler, Request, Response } from 'express';\nimport type { UserConfig, ViteDevServer } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport interface ViteStats {}\n\nexport type ViteBuilder = Builder<UserConfig, ViteStats>;\n\nfunction iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): RequestHandler {\n return async (req, res, next) => {\n if (!req.url.match(/^\\/iframe\\.html($|\\?)/)) {\n next();\n return;\n }\n\n // We need to handle `html-proxy` params for style tag HMR https://github.com/storybookjs/builder-vite/issues/266#issuecomment-1055677865\n // e.g. /iframe.html?html-proxy&index=0.css\n if (req.query['html-proxy'] !== undefined) {\n next();\n return;\n }\n\n const indexHtml = fs.readFileSync(path.resolve(__dirname, '..', 'input', 'iframe.html'), 'utf-8');\n const generated = await transformIframeHtml(indexHtml, options);\n const transformed = await server.transformIndexHtml('/iframe.html', generated);\n res.setHeader('Content-Type', 'text/html');\n res.status(200).send(transformed);\n };\n}\n\nexport const start: ViteBuilder['start'] = async ({ startTime, options, router, server: devServer }) => {\n const server = await createViteServer(options as ExtendedOptions, devServer);\n\n // Just mock this endpoint (which is really Webpack-specific) so we don't get spammed with 404 in browser devtools\n // TODO: we should either show some sort of progress from Vite, or just try to disable the whole Loader in the Manager UI.\n router.get('/progress', (req: Request, res: Response) => {\n res.header('Cache-Control', 'no-cache');\n res.header('Content-Type', 'text/event-stream');\n });\n\n router.use(await iframeMiddleware(options as ExtendedOptions, server));\n router.use(server.middlewares);\n\n async function bail(e?: Error): Promise<void> {\n try {\n return await server.close();\n } catch (err) {\n console.warn('unable to close vite server');\n }\n\n throw e;\n }\n\n return {\n bail,\n stats: {} as ViteStats,\n totalTime: process.hrtime(startTime),\n };\n};\n\nexport const build: ViteBuilder['build'] = async ({ options }) => {\n return viteBuild(options as ExtendedOptions);\n};\n\nexport const corePresets = [];\nexport const previewPresets = [];\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;AAErC,uCAAyB;AACzB,2CAA6B;AAC7B,mEAA8D;AAC9D,+CAAiD;AACjD,mCAA6C;AAiB7C,SAAS,gBAAgB,CAAC,OAAwB,EAAE,MAAqB;IACvE,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,EAAE;YAC3C,IAAI,EAAE,CAAC;YACP,OAAO;SACR;QAED,yIAAyI;QACzI,2CAA2C;QAC3C,IAAI,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE;YACzC,IAAI,EAAE,CAAC;YACP,OAAO;SACR;QAED,MAAM,SAAS,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC;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AC,MAAM,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC,CAAC;AA5BW,QAAA,KAAK,SA4BhB;AAEK,MAAM,KAAK,GAAyB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IAC/D,OAAO,IAAA,aAAS,EAAC,OAA0B,CAAC,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB;AAEW,QAAA,WAAW,GAAG,EAAE,CAAC;AACjB,QAAA,cAAc,GAAG,EAAE,CAAC","sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { transformIframeHtml } from './transform-iframe-html';\nimport { createViteServer } from './vite-server';\nimport { build as viteBuild } from './build';\n\nimport type { Builder, StorybookConfig } from '@storybook/core-common';\nimport type { RequestHandler, Request, Response } from 'express';\nimport type { InlineConfig, UserConfig, ViteDevServer } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport interface ViteStats {}\n\nexport type ViteBuilder = Builder<UserConfig, ViteStats>;\n\nexport type ViteFinal = (config: InlineConfig, options: StorybookConfig) => InlineConfig | Promise<InlineConfig>;\n\nexport type StorybookViteConfig = StorybookConfig & {\n viteFinal: ViteFinal;\n};\n\nfunction iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): RequestHandler {\n return async (req, res, next) => {\n if (!req.url.match(/^\\/iframe\\.html($|\\?)/)) {\n next();\n return;\n }\n\n // We need to handle `html-proxy` params for style tag HMR https://github.com/storybookjs/builder-vite/issues/266#issuecomment-1055677865\n // e.g. /iframe.html?html-proxy&index=0.css\n if (req.query['html-proxy'] !== undefined) {\n next();\n return;\n }\n\n const indexHtml = fs.readFileSync(path.resolve(__dirname, '..', 'input', 'iframe.html'), 'utf-8');\n const generated = await transformIframeHtml(indexHtml, options);\n const transformed = await server.transformIndexHtml('/iframe.html', generated);\n res.setHeader('Content-Type', 'text/html');\n res.status(200).send(transformed);\n };\n}\n\nexport const start: ViteBuilder['start'] = async ({ startTime, options, router, server: devServer }) => {\n const server = await createViteServer(options as ExtendedOptions, devServer);\n\n // Just mock this endpoint (which is really Webpack-specific) so we don't get spammed with 404 in browser devtools\n // TODO: we should either show some sort of progress from Vite, or just try to disable the whole Loader in the Manager UI.\n router.get('/progress', (req: Request, res: Response) => {\n res.header('Cache-Control', 'no-cache');\n res.header('Content-Type', 'text/event-stream');\n });\n\n router.use(await iframeMiddleware(options as ExtendedOptions, server));\n router.use(server.middlewares);\n\n async function bail(e?: Error): Promise<void> {\n try {\n return await server.close();\n } catch (err) {\n console.warn('unable to close vite server');\n }\n\n throw e;\n }\n\n return {\n bail,\n stats: {} as ViteStats,\n totalTime: process.hrtime(startTime),\n };\n};\n\nexport const build: ViteBuilder['build'] = async ({ options }) => {\n return viteBuild(options as ExtendedOptions);\n};\n\nexport const corePresets = [];\nexport const previewPresets = [];\n"]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"list-stories.js","sourceRoot":"","sources":["../list-stories.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+CAA+C;AAC/C,wDAA0D;AAInD,KAAK,UAAU,WAAW,CAAC,OAAgB;IAChD,OAAO,CACL,MAAM,OAAO,CAAC,GAAG,CACf,IAAA,8BAAgB,EAAC,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE;QACpE,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,UAAU,EAAE,OAAO,CAAC,SAAS;KAC9B,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAE5C,OAAO,IAAA,sBAAI,EAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC,CACH,CACF,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC;AAbD,kCAaC","sourcesContent":["import * as path from 'path';\nimport { promise as glob } from 'glob-promise';\nimport { normalizeStories } from '@storybook/core-common';\n\nimport type { Options } from '@storybook/core-common';\n\nexport async function listStories(options: Options) {\n return (\n await Promise.all(\n normalizeStories(await options.presets.apply('stories', [], options), {\n configDir: options.configDir,\n workingDir: options.configDir,\n }).map(({ directory, files }) => {\n const pattern = path.join(directory, files);\n\n return glob(path.isAbsolute(pattern) ? pattern : path.join(options.configDir, pattern));\n })\n )\n ).reduce((carry, stories) => carry.concat(stories), []);\n}\n"]}
1
+ {"version":3,"file":"list-stories.js","sourceRoot":"","sources":["../list-stories.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+CAA+C;AAC/C,wDAA0D;AAInD,KAAK,UAAU,WAAW,CAAC,OAAgB;IAChD,OAAO,CACL,MAAM,OAAO,CAAC,GAAG,CACf,IAAA,8BAAgB,EAAC,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE;QACpE,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,UAAU,EAAE,OAAO,CAAC,SAAS;KAC9B,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAE5C,OAAO,IAAA,sBAAI,EAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC,CACH,CACF,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC;AAbD,kCAaC","sourcesContent":["import * as path from 'path';\nimport { promise as glob } from 'glob-promise';\nimport { normalizeStories } from '@storybook/core-common';\n\nimport type { Options } from '@storybook/core-common';\n\nexport async function listStories(options: Options) {\n return (\n await Promise.all(\n normalizeStories(await options.presets.apply('stories', [], options), {\n configDir: options.configDir,\n workingDir: options.configDir,\n }).map(({ directory, files }) => {\n const pattern = path.join(directory, files);\n\n return glob(path.isAbsolute(pattern) ? pattern : path.join(options.configDir, pattern));\n })\n )\n ).reduce((carry, stories) => carry.concat(stories), []);\n}\n"]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"optimizeDeps.js","sourceRoot":"","sources":["../optimizeDeps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+BAAgE;AAChE,iDAA6C;AAI7C,MAAM,kBAAkB,GAAG;IACzB,4BAA4B;IAC5B,eAAe;IACf,wBAAwB;IACxB,iBAAiB;IACjB,eAAe;IACf,mCAAmC;IACnC,uBAAuB;IACvB,mBAAmB;IACnB,gCAAgC;IAChC,8BAA8B;IAC9B,uBAAuB;IACvB,0BAA0B;IAC1B,wBAAwB;IACxB,gBAAgB;IAChB,wBAAwB;IACxB,8BAA8B;IAC9B,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;IACjB,WAAW;IACX,YAAY;IACZ,OAAO;IACP,iBAAiB;IACjB,cAAc;IACd,UAAU;IACV,eAAe;IACf,kBAAkB;IAClB,UAAU;IACV,iBAAiB;IACjB,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,QAAQ;IACR,WAAW;IACX,UAAU;IACV,WAAW;IACX,cAAc;IACd,kBAAkB;IAClB,mBAAmB;IACnB,sBAAsB;IACtB,iBAAiB;IACjB,gBAAgB;IAChB,kBAAkB;IAClB,aAAa;IACb,eAAe;IACf,kBAAkB;IAClB,iBAAiB;IACjB,aAAa;IACb,iBAAiB;IACjB,cAAc;IACd,mBAAmB;IACnB,UAAU;IACV,uBAAuB;IACvB,sBAAsB;IACtB,4BAA4B;IAC5B,YAAY;IACZ,IAAI;IACJ,WAAW;IACX,kBAAkB;IAClB,oBAAoB;IACpB,UAAU;IACV,yBAAyB;IACzB,OAAO;IACP,gBAAgB;IAChB,wBAAwB;IACxB,uBAAuB;IACvB,2BAA2B;IAC3B,6BAA6B;IAC7B,wB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C,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACnD,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SAClC;KACF;IAED,6FAA6F;IAC7F,uIAAuI;IACvI,MAAM,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEhG,OAAO;QACL,2EAA2E;QAC3E,OAAO,EAAE,OAAO;QAChB,oGAAoG;QACpG,2CAA2C;QAC3C,OAAO;QACP,+DAA+D;QAC/D,OAAO;KACR,CAAC;AACJ,CAAC;AAlCD,0CAkCC;AAED,kEAAkE;AAClE,MAAM,WAAW,GAAG,CAAC,KAAc,EAAkC,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC","sourcesContent":["import * as path from 'path';\nimport { normalizePath, resolveConfig, UserConfig } from 'vite';\nimport { listStories } from './list-stories';\n\nimport type { ExtendedOptions } from './types';\n\nconst INCLUDE_CANDIDATES = [\n '@base2/pretty-print-object',\n '@emotion/core',\n '@emotion/is-prop-valid',\n '@emotion/styled',\n '@mdx-js/react',\n '@storybook/addon-docs > acorn-jsx',\n '@storybook/addon-docs',\n '@storybook/addons',\n '@storybook/channel-postmessage',\n '@storybook/channel-websocket',\n '@storybook/client-api',\n '@storybook/client-logger',\n '@storybook/core/client',\n '@storybook/csf',\n '@storybook/preview-web',\n '@storybook/react > acorn-jsx',\n '@storybook/react',\n '@storybook/svelte',\n '@storybook/vue3',\n 'acorn-jsx',\n 'acorn-walk',\n 'acorn',\n 'airbnb-js-shims',\n 'ansi-to-html',\n 'axe-core',\n 'color-convert',\n 'deep-object-diff',\n 'doctrine',\n 'emotion-theming',\n 'escodegen',\n 'estraverse',\n 'fast-deep-equal',\n 'global',\n 'html-tags',\n 'isobject',\n 'jest-mock',\n 'loader-utils',\n 'lodash/cloneDeep',\n 'lodash/isFunction',\n 'lodash/isPlainObject',\n 'lodash/isString',\n 'lodash/mapKeys',\n 'lodash/mapValues',\n 'lodash/pick',\n 'lodash/pickBy',\n 'lodash/startCase',\n 'lodash/throttle',\n 'lodash/uniq',\n 'markdown-to-jsx',\n 'memoizerific',\n 'overlayscrollbars',\n 'polished',\n 'prettier/parser-babel',\n 'prettier/parser-flow',\n 'prettier/parser-typescript',\n 'prop-types',\n 'qs',\n 'react-dom',\n 'react-dom/client',\n 'react-fast-compare',\n 'react-is',\n 'react-textarea-autosize',\n 'react',\n 'refractor/core',\n 'refractor/lang/bash.js',\n 'refractor/lang/css.js',\n 'refractor/lang/graphql.js',\n 'refractor/lang/js-extras.js',\n 'refractor/lang/json.js',\n 'refractor/lang/jsx.js',\n 'refractor/lang/markdown.js',\n 'refractor/lang/markup.js',\n 'refractor/lang/tsx.js',\n 'refractor/lang/typescript.js',\n 'refractor/lang/yaml.js',\n 'regenerator-runtime/runtime.js',\n 'slash',\n 'stable',\n 'store2',\n 'synchronous-promise',\n 'telejson',\n 'ts-dedent',\n 'unfetch',\n 'util-deprecate',\n 'uuid-browser/v4',\n 'vue',\n 'warning',\n];\n\n/**\n * Helper function which allows us to `filter` with an async predicate. Uses Promise.all for performance.\n */\nconst asyncFilter = async (arr: string[], predicate: (val: string) => Promise<boolean>) =>\n Promise.all(arr.map(predicate)).then((results) => arr.filter((_v, index) => results[index]));\n\nexport async function getOptimizeDeps(\n config: UserConfig & { configFile: false; root: string },\n options: ExtendedOptions\n) {\n const { root } = config;\n const absoluteStories = await listStories(options);\n const stories = absoluteStories.map((storyPath) => normalizePath(path.relative(root, storyPath)));\n const resolvedConfig = await resolveConfig(config, 'serve', 'development');\n\n const exclude = [];\n // This is necessary to support react < 18 with new versions of @storybook/react that support react 18.\n // TODO: narrow this down to just framework === 'react'. But causes a vue dev start problem in this monorepo.\n try {\n require.resolve('react-dom/client', { paths: [config.root] });\n } catch (e) {\n if (isNodeError(e) && e.code === 'MODULE_NOT_FOUND') {\n exclude.push('react-dom/client');\n }\n }\n\n // This function converts ids which might include ` > ` to a real path, if it exists on disk.\n // See https://github.com/vitejs/vite/blob/67d164392e8e9081dc3f0338c4b4b8eea6c5f7da/packages/vite/src/node/optimizer/index.ts#L182-L199\n const resolve = resolvedConfig.createResolver({ asSrc: false });\n const include = await asyncFilter(INCLUDE_CANDIDATES, async (id) => Boolean(await resolve(id)));\n\n return {\n // We don't need to resolve the glob since vite supports globs for entries.\n entries: stories,\n // We need Vite to precompile these dependencies, because they contain non-ESM code that would break\n // if we served it directly to the browser.\n include,\n // In some cases we need to prevent deps from being pre-bundled\n exclude,\n };\n}\n\n// Refines an error received from 'catch' to be a NodeJS exception\nconst isNodeError = (error: unknown): error is NodeJS.ErrnoException => error instanceof Error;\n"]}
1
+ {"version":3,"file":"optimizeDeps.js","sourceRoot":"","sources":["../optimizeDeps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+BAAgE;AAChE,iDAA6C;AAI7C,MAAM,kBAAkB,GAAG;IACzB,4BAA4B;IAC5B,eAAe;IACf,wBAAwB;IACxB,iBAAiB;IACjB,eAAe;IACf,mCAAmC;IACnC,uBAAuB;IACvB,mBAAmB;IACnB,gCAAgC;IAChC,8BAA8B;IAC9B,uBAAuB;IACvB,0BAA0B;IAC1B,wBAAwB;IACxB,gBAAgB;IAChB,wBAAwB;IACxB,8BAA8B;IAC9B,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;IACjB,WAAW;IACX,YAAY;IACZ,OAAO;IACP,iBAAiB;IACjB,cAAc;IACd,UAAU;IACV,eAAe;IACf,kBAAkB;IAClB,UAAU;IACV,iBAAiB;IACjB,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,QAAQ;IACR,WAAW;IACX,UAAU;IACV,WAAW;IACX,cAAc;IACd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A,oBAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAClG,MAAM,cAAc,GAAG,MAAM,IAAA,oBAAa,EAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IAE3E,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,uGAAuG;IACvG,8GAA8G;IAC9G,IAAI;QACF,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KAC/D;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACnD,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SAClC;KACF;IAED,6FAA6F;IAC7F,uIAAuI;IACvI,MAAM,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEhG,OAAO;QACL,2EAA2E;QAC3E,OAAO,EAAE,OAAO;QAChB,oGAAoG;QACpG,2CAA2C;QAC3C,OAAO;QACP,+DAA+D;QAC/D,OAAO;KACR,CAAC;AACJ,CAAC;AAlCD,0CAkCC;AAED,kEAAkE;AAClE,MAAM,WAAW,GAAG,CAAC,KAAc,EAAkC,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC","sourcesContent":["import * as path from 'path';\nimport { normalizePath, resolveConfig, UserConfig } from 'vite';\nimport { listStories } from './list-stories';\n\nimport type { ExtendedOptions } from './types';\n\nconst INCLUDE_CANDIDATES = [\n '@base2/pretty-print-object',\n '@emotion/core',\n '@emotion/is-prop-valid',\n '@emotion/styled',\n '@mdx-js/react',\n '@storybook/addon-docs > acorn-jsx',\n '@storybook/addon-docs',\n '@storybook/addons',\n '@storybook/channel-postmessage',\n '@storybook/channel-websocket',\n '@storybook/client-api',\n '@storybook/client-logger',\n '@storybook/core/client',\n '@storybook/csf',\n '@storybook/preview-web',\n '@storybook/react > acorn-jsx',\n '@storybook/react',\n '@storybook/svelte',\n '@storybook/vue3',\n 'acorn-jsx',\n 'acorn-walk',\n 'acorn',\n 'airbnb-js-shims',\n 'ansi-to-html',\n 'axe-core',\n 'color-convert',\n 'deep-object-diff',\n 'doctrine',\n 'emotion-theming',\n 'escodegen',\n 'estraverse',\n 'fast-deep-equal',\n 'global',\n 'html-tags',\n 'isobject',\n 'jest-mock',\n 'loader-utils',\n 'lodash/cloneDeep',\n 'lodash/isFunction',\n 'lodash/isPlainObject',\n 'lodash/isString',\n 'lodash/mapKeys',\n 'lodash/mapValues',\n 'lodash/pick',\n 'lodash/pickBy',\n 'lodash/startCase',\n 'lodash/throttle',\n 'lodash/uniq',\n 'markdown-to-jsx',\n 'memoizerific',\n 'overlayscrollbars',\n 'polished',\n 'prettier/parser-babel',\n 'prettier/parser-flow',\n 'prettier/parser-typescript',\n 'prop-types',\n 'qs',\n 'react-dom',\n 'react-dom/client',\n 'react-fast-compare',\n 'react-is',\n 'react-textarea-autosize',\n 'react',\n 'refractor/core',\n 'refractor/lang/bash.js',\n 'refractor/lang/css.js',\n 'refractor/lang/graphql.js',\n 'refractor/lang/js-extras.js',\n 'refractor/lang/json.js',\n 'refractor/lang/jsx.js',\n 'refractor/lang/markdown.js',\n 'refractor/lang/markup.js',\n 'refractor/lang/tsx.js',\n 'refractor/lang/typescript.js',\n 'refractor/lang/yaml.js',\n 'regenerator-runtime/runtime.js',\n 'slash',\n 'stable',\n 'store2',\n 'synchronous-promise',\n 'telejson',\n 'ts-dedent',\n 'unfetch',\n 'util-deprecate',\n 'uuid-browser/v4',\n 'vue',\n 'warning',\n];\n\n/**\n * Helper function which allows us to `filter` with an async predicate. Uses Promise.all for performance.\n */\nconst asyncFilter = async (arr: string[], predicate: (val: string) => Promise<boolean>) =>\n Promise.all(arr.map(predicate)).then((results) => arr.filter((_v, index) => results[index]));\n\nexport async function getOptimizeDeps(\n config: UserConfig & { configFile: false; root: string },\n options: ExtendedOptions\n) {\n const { root } = config;\n const absoluteStories = await listStories(options);\n const stories = absoluteStories.map((storyPath) => normalizePath(path.relative(root, storyPath)));\n const resolvedConfig = await resolveConfig(config, 'serve', 'development');\n\n const exclude = [];\n // This is necessary to support react < 18 with new versions of @storybook/react that support react 18.\n // TODO: narrow this down to just framework === 'react'. But causes a vue dev start problem in this monorepo.\n try {\n require.resolve('react-dom/client', { paths: [config.root] });\n } catch (e) {\n if (isNodeError(e) && e.code === 'MODULE_NOT_FOUND') {\n exclude.push('react-dom/client');\n }\n }\n\n // This function converts ids which might include ` > ` to a real path, if it exists on disk.\n // See https://github.com/vitejs/vite/blob/67d164392e8e9081dc3f0338c4b4b8eea6c5f7da/packages/vite/src/node/optimizer/index.ts#L182-L199\n const resolve = resolvedConfig.createResolver({ asSrc: false });\n const include = await asyncFilter(INCLUDE_CANDIDATES, async (id) => Boolean(await resolve(id)));\n\n return {\n // We don't need to resolve the glob since vite supports globs for entries.\n entries: stories,\n // We need Vite to precompile these dependencies, because they contain non-ESM code that would break\n // if we served it directly to the browser.\n include,\n // In some cases we need to prevent deps from being pre-bundled\n exclude,\n };\n}\n\n// Refines an error received from 'catch' to be a NodeJS exception\nconst isNodeError = (error: unknown): error is NodeJS.ErrnoException => error instanceof Error;\n"]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"csf-plugin.js","sourceRoot":"","sources":["../../svelte/csf-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,6GAAwG;AACxG,2BAAkC;AAClC,iGAA6F;AAC7F,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,6DAA6D,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAErH,wDAA0C;AAE1C,SAAwB,SAAS,CAAC,aAAuB;IACvD,OAAO;QACL,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,MAAM;QACf,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,EAAU;YACtC,IAAI,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACjC,MAAM,SAAS,GAAG,IAAA,2CAAmB,EAAC,EAAE,CAAC,CAAC;gBAC1C,IAAI,MAAM,GAAG,IAAA,iBAAY,EAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;gBACzC,IAAI,aAAa,IAAI,aAAa,CAAC,UAAU,EAAE;oBAC7C,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;iBAC7F;gBACD,MAAM,GAAG,GAAG,IAAA,gCAAc,EAAC,MAAM,CAAC,CAAC;gBACnC,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;gBACxB,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAM,OAAO,CAAC;qBAC1C,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;qBAClC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,gBAAgB,EAAE,gCAAgC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC;qBACvF,IAAI,CAAC,IAAI,CAAC,CAAC;gBAEd,MAAM,wBAAwB,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;gBAEvF,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAM,OAAO,CAAC;qBACnD,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;qBAClC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;gBAErB,MAAM,MAAM,GAAG;oBACb,wBAAwB;oBACxB,uBAAuB,MAAM,IAAI;oBACjC,oCAAoC,SAAS,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI;oBACzE,wCAAwC;oBACxC,sCAAsC,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,GAAG;oBAC1E,QAAQ;iBACT,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACb,OAAO;oBACL,IAAI,EAAE,MAAM;iBACb,CAAC;aACH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAtCD,4BAsCC","sourcesContent":["import { getNameFromFilename } from '@storybook/addon-svelte-csf/dist/cjs/parser/svelte-stories-loader';\nimport { readFileSync } from 'fs';\nimport { extractStories } from '@storybook/addon-svelte-csf/dist/cjs/parser/extract-stories';\nconst parser = require.resolve('@storybook/addon-svelte-csf/dist/esm/parser/collect-stories').replace(/[/\\\\]/g, '/');\nimport type { Options } from '@sveltejs/vite-plugin-svelte';\nimport * as svelte from 'svelte/compiler';\n\nexport default function csfPlugin(svelteOptions?: Options) {\n return {\n name: 'storybook-addon-svelte-csf',\n enforce: 'post',\n async transform(code: string, id: string) {\n if (/\\.stories\\.svelte$/.test(id)) {\n const component = getNameFromFilename(id);\n let source = readFileSync(id).toString();\n if (svelteOptions && svelteOptions.preprocess) {\n source = (await svelte.preprocess(source, svelteOptions.preprocess, { filename: id })).code;\n }\n const all = extractStories(source);\n const { stories } = all;\n const storyDef = Object.entries<any>(stories)\n .filter(([, def]) => !def.template)\n .map(([id]) => `export const ${id} = __storiesMetaData.stories[${JSON.stringify(id)}];`)\n .join('\\n');\n\n const codeWithoutDefaultExport = code.replace('export default ', '// export default ');\n\n const namedExportsOrder = Object.entries<any>(stories)\n .filter(([, def]) => !def.template)\n .map(([id]) => id);\n\n const output = [\n codeWithoutDefaultExport,\n `import parser from '${parser}';`,\n `const __storiesMetaData = parser(${component}, ${JSON.stringify(all)});`,\n 'export default __storiesMetaData.meta;',\n `export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`,\n storyDef,\n ].join('\\n');\n return {\n code: output,\n };\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"csf-plugin.js","sourceRoot":"","sources":["../../svelte/csf-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6GAAwG;AACxG,2BAAkC;AAClC,iGAA6F;AAC7F,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,6DAA6D,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAErH,wDAA0C;AAE1C,SAAwB,SAAS,CAAC,aAAuB;IACvD,OAAO;QACL,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,MAAM;QACf,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,EAAU;YACtC,IAAI,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACjC,MAAM,SAAS,GAAG,IAAA,2CAAmB,EAAC,EAAE,CAAC,CAAC;gBAC1C,IAAI,MAAM,GAAG,IAAA,iBAAY,EAAC,EAAE,CAAC,CAA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;iBACT,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACb,OAAO;oBACL,IAAI,EAAE,MAAM;iBACb,CAAC;aACH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAtCD,4BAsCC","sourcesContent":["import { getNameFromFilename } from '@storybook/addon-svelte-csf/dist/cjs/parser/svelte-stories-loader';\nimport { readFileSync } from 'fs';\nimport { extractStories } from '@storybook/addon-svelte-csf/dist/cjs/parser/extract-stories';\nconst parser = require.resolve('@storybook/addon-svelte-csf/dist/esm/parser/collect-stories').replace(/[/\\\\]/g, '/');\nimport type { Options } from '@sveltejs/vite-plugin-svelte';\nimport * as svelte from 'svelte/compiler';\n\nexport default function csfPlugin(svelteOptions?: Options) {\n return {\n name: 'storybook-addon-svelte-csf',\n enforce: 'post',\n async transform(code: string, id: string) {\n if (/\\.stories\\.svelte$/.test(id)) {\n const component = getNameFromFilename(id);\n let source = readFileSync(id).toString();\n if (svelteOptions && svelteOptions.preprocess) {\n source = (await svelte.preprocess(source, svelteOptions.preprocess, { filename: id })).code;\n }\n const all = extractStories(source);\n const { stories } = all;\n const storyDef = Object.entries<any>(stories)\n .filter(([, def]) => !def.template)\n .map(([id]) => `export const ${id} = __storiesMetaData.stories[${JSON.stringify(id)}];`)\n .join('\\n');\n\n const codeWithoutDefaultExport = code.replace('export default ', '// export default ');\n\n const namedExportsOrder = Object.entries<any>(stories)\n .filter(([, def]) => !def.template)\n .map(([id]) => id);\n\n const output = [\n codeWithoutDefaultExport,\n `import parser from '${parser}';`,\n `const __storiesMetaData = parser(${component}, ${JSON.stringify(all)});`,\n 'export default __storiesMetaData.meta;',\n `export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`,\n storyDef,\n ].join('\\n');\n return {\n code: output,\n };\n }\n },\n };\n}\n"]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,0DAAwC","sourcesContent":["export * from './envs-raw.type';\nexport * from './extended-options.type';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,0DAAwC","sourcesContent":["export * from './envs-raw.type';\nexport * from './extended-options.type';\n"]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAEpB,iCAAuD;AAEvD,iDAA4C;AAC5C,mEAA8D;AAC9D,6EAAuE;AACvE,6CAAyC;AACzC,+CAA2C;AAC3C,iEAA4D;AAO5D,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'fs';\nimport { Plugin } from 'vite';\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport { mockCoreJs } from './mock-core-js';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './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 = await presets.apply('svelteOptions', {}, options);\n\n const plugins = [\n codeGeneratorPlugin(options),\n mockCoreJs(),\n sourceLoaderPlugin(),\n mdxPlugin(),\n noFouc(),\n injectExportOrderPlugin,\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 plugins.push(sveltePlugin(svelteOptions));\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 plugins.push(csfPlugin(svelteOptions));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @storybook/addon-svelte-csf to be installed when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n\n if (framework === 'react') {\n plugins.push(\n require('@vitejs/plugin-react')({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/],\n })\n );\n\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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,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;AA5FD,oCA4FC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport { mockCoreJs } from './mock-core-js';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './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 = await presets.apply('svelteOptions', {}, options);\n\n const plugins = [\n codeGeneratorPlugin(options),\n mockCoreJs(),\n sourceLoaderPlugin(),\n mdxPlugin(),\n noFouc(),\n injectExportOrderPlugin,\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 plugins.push(sveltePlugin(svelteOptions));\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 plugins.push(csfPlugin(svelteOptions));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @storybook/addon-svelte-csf to be installed when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n\n if (framework === 'react') {\n plugins.push(\n require('@vitejs/plugin-react')({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/],\n })\n );\n\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"]}
package/index.ts CHANGED
@@ -6,15 +6,21 @@ import { transformIframeHtml } from './transform-iframe-html';
6
6
  import { createViteServer } from './vite-server';
7
7
  import { build as viteBuild } from './build';
8
8
 
9
- import type { Builder } from '@storybook/core-common';
9
+ import type { Builder, StorybookConfig } from '@storybook/core-common';
10
10
  import type { RequestHandler, Request, Response } from 'express';
11
- import type { UserConfig, ViteDevServer } from 'vite';
11
+ import type { InlineConfig, UserConfig, ViteDevServer } from 'vite';
12
12
  import type { ExtendedOptions } from './types';
13
13
 
14
14
  export interface ViteStats {}
15
15
 
16
16
  export type ViteBuilder = Builder<UserConfig, ViteStats>;
17
17
 
18
+ export type ViteFinal = (config: InlineConfig, options: StorybookConfig) => InlineConfig | Promise<InlineConfig>;
19
+
20
+ export type StorybookViteConfig = StorybookConfig & {
21
+ viteFinal: ViteFinal;
22
+ };
23
+
18
24
  function iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): RequestHandler {
19
25
  return async (req, res, next) => {
20
26
  if (!req.url.match(/^\/iframe\.html($|\?)/)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
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",