@storybook/builder-vite 0.2.6 → 0.2.7
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/code-generator-plugin.ts +1 -1
- package/codegen-importfn-script.ts +1 -1
- package/dist/code-generator-plugin.js +1 -1
- package/dist/code-generator-plugin.js.map +1 -1
- package/dist/codegen-importfn-script.js +1 -1
- package/dist/codegen-importfn-script.js.map +1 -1
- package/dist/inject-export-order-plugin.js +1 -1
- package/dist/inject-export-order-plugin.js.map +1 -1
- package/dist/plugins/vue-docgen.js +1 -1
- package/dist/plugins/vue-docgen.js.map +1 -1
- package/dist/source-loader-plugin.js +1 -1
- package/dist/source-loader-plugin.js.map +1 -1
- package/dist/vite-config.js +1 -1
- package/dist/vite-config.js.map +1 -1
- package/inject-export-order-plugin.ts +1 -1
- package/package.json +1 -1
- package/plugins/vue-docgen.ts +1 -1
- package/source-loader-plugin.ts +1 -1
- package/vite-config.ts +1 -1
package/code-generator-plugin.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
|
|
|
39
39
|
// HMR to update the importFn.
|
|
40
40
|
server.watcher.on('add', (path) => {
|
|
41
41
|
// TODO maybe use the stories declaration in main
|
|
42
|
-
if (/\.stories\.([tj])
|
|
42
|
+
if (/\.stories\.(?:[tj]sx?|vue)$/.test(path) || /\.(story|stories).mdx$/.test(path)) {
|
|
43
43
|
// We need to emit a change event to trigger HMR
|
|
44
44
|
server.watcher.emit('change', virtualStoriesFile);
|
|
45
45
|
}
|
|
@@ -29,7 +29,7 @@ async function toImportFn(stories: string[]) {
|
|
|
29
29
|
const objectEntries = stories.map((file) => {
|
|
30
30
|
const ext = path.extname(file);
|
|
31
31
|
const relativePath = normalizePath(path.relative(process.cwd(), file));
|
|
32
|
-
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx'].includes(ext)) {
|
|
32
|
+
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx', '.vue'].includes(ext)) {
|
|
33
33
|
logger.warn(`Cannot process ${ext} file with storyStoreV7: ${relativePath}`);
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -58,7 +58,7 @@ function codeGeneratorPlugin(options) {
|
|
|
58
58
|
// HMR to update the importFn.
|
|
59
59
|
server.watcher.on('add', (path) => {
|
|
60
60
|
// TODO maybe use the stories declaration in main
|
|
61
|
-
if (/\.stories\.([tj])
|
|
61
|
+
if (/\.stories\.(?:[tj]sx?|vue)$/.test(path) || /\.(story|stories).mdx$/.test(path)) {
|
|
62
62
|
// We need to emit a change event to trigger HMR
|
|
63
63
|
server.watcher.emit('change', virtual_file_names_1.virtualStoriesFile);
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-generator-plugin.js","sourceRoot":"","sources":["../code-generator-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,+BAAmC;AACnC,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;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,GAAG,EAAE;gBAC/B,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,kCAAa,CAAC,CAAC;gBAClE,IAAI,SAAS,EAAE;oBACb,MAAM,CAAC,WAAW,CAAC,gBAAgB,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,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;AAjHD,kDAiHC;AAED,kEAAkE;AAClE,MAAM,WAAW,GAAG,CAAC,KAAc,EAAkC,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { mergeConfig } from 'vite';\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\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', () => {\n const appModule = server.moduleGraph.getModuleById(virtualFileId);\n if (appModule) {\n server.moduleGraph.invalidateModule(appModule);\n }\n const storiesModule = server.moduleGraph.getModuleById(virtualStoriesFile);\n if (storiesModule) {\n server.moduleGraph.invalidateModule(storiesModule);\n }\n });\n\n // Adding new story files is not covered by the change event above. So we need to detect this and trigger\n // HMR to update the importFn.\n server.watcher.on('add', (path) => {\n // TODO maybe use the stories declaration in main\n if (/\\.stories\\.(?:[tj]sx?|vue)$/.test(path) || /\\.(story|stories).mdx$/.test(path)) {\n // We need to emit a change event to trigger HMR\n server.watcher.emit('change', virtualStoriesFile);\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 // Detect if react 18 is installed. If not, alias it to a virtual placeholder file.\n try {\n require.resolve('react-dom/client', { paths: [config.root || process.cwd()] });\n } catch (e) {\n if (isNodeError(e) && e.code === 'MODULE_NOT_FOUND') {\n config.resolve = mergeConfig(config.resolve ?? {}, {\n alias: {\n 'react-dom/client': path.resolve(__dirname, '..', 'input', 'react-dom-client-placeholder.js'),\n },\n });\n }\n }\n },\n configResolved(config) {\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 }\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\n// Refines an error received from 'catch' to be a NodeJS exception\nconst isNodeError = (error: unknown): error is NodeJS.ErrnoException => error instanceof Error;\n"]}
|
|
@@ -50,7 +50,7 @@ async function toImportFn(stories) {
|
|
|
50
50
|
const objectEntries = stories.map((file) => {
|
|
51
51
|
const ext = path.extname(file);
|
|
52
52
|
const relativePath = (0, vite_1.normalizePath)(path.relative(process.cwd(), file));
|
|
53
|
-
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx'].includes(ext)) {
|
|
53
|
+
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx', '.vue'].includes(ext)) {
|
|
54
54
|
node_logger_1.logger.warn(`Cannot process ${ext} file with storyStoreV7: ${relativePath}`);
|
|
55
55
|
}
|
|
56
56
|
return ` '${toImportPath(relativePath)}': async () => import('/@fs/${file}')`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-importfn-script.js","sourceRoot":"","sources":["../codegen-importfn-script.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+BAAqC;AAErC,wDAAgD;AAEhD,iDAA6C;AAE7C;;GAEG;AAEH;;;;GAIG;AACH,SAAS,YAAY,CAAC,YAAoB;IACxC,OAAO,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAA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E,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACjE,oBAAM,CAAC,IAAI,CAAC,kBAAkB,GAAG,4BAA4B,YAAY,EAAE,CAAC,CAAC;SAC9E;QAED,OAAO,MAAM,YAAY,CAAC,YAAY,CAAC,+BAA+B,IAAI,IAAI,CAAC;IACjF,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';\nimport { logger } from '@storybook/node-logger';\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 const ext = path.extname(file);\n const relativePath = normalizePath(path.relative(process.cwd(), file));\n if (!['.js', '.jsx', '.ts', '.tsx', '.mdx', '.vue'].includes(ext)) {\n logger.warn(`Cannot process ${ext} file with storyStoreV7: ${relativePath}`);\n }\n\n return ` '${toImportPath(relativePath)}': 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"]}
|
|
@@ -11,7 +11,7 @@ exports.injectExportOrderPlugin = {
|
|
|
11
11
|
// This should only run after the typescript has been transpiled
|
|
12
12
|
enforce: 'post',
|
|
13
13
|
async transform(code, id) {
|
|
14
|
-
if (!/\.stories\.([tj])
|
|
14
|
+
if (!/\.stories\.(?:[tj]sx?|vue)$/.test(id) && !/(stories|story).mdx$/.test(id)) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
// TODO: Maybe convert `injectExportOrderPlugin` to function that returns object,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-export-order-plugin.js","sourceRoot":"","sources":["../inject-export-order-plugin.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAwC;AACxC,gEAAuC;AAE1B,QAAA,uBAAuB,GAAG;IACrC,IAAI,EAAE,2CAA2C;IACjD,gEAAgE;IAChE,OAAO,EAAE,MAAM;IACf,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,EAAU;QACtC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"inject-export-order-plugin.js","sourceRoot":"","sources":["../inject-export-order-plugin.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAwC;AACxC,gEAAuC;AAE1B,QAAA,uBAAuB,GAAG;IACrC,IAAI,EAAE,2CAA2C;IACjD,gEAAgE;IAChE,OAAO,EAAE,MAAM;IACf,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,EAAU;QACtC,IAAI,CAAC,6BAA6B,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YAC/E,OAAO;SACR;QACD,iFAAiF;QACjF,uEAAuE;QACvE,kDAAkD;QAClD,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,MAAM,IAAA,uBAAK,EAAC,IAAI,CAAC,CAAC;QAEtC,IAAI,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE;YAC3C,yCAAyC;YACzC,OAAO;SACR;QACD,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;QAC9D,CAAC,CAAC,MAAM,CAAC,uCAAuC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACnF,OAAO;YACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;YAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;SAChD,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { parse } from 'es-module-lexer';\nimport MagicString from 'magic-string';\n\nexport const injectExportOrderPlugin = {\n name: 'storybook-vite-inject-export-order-plugin',\n // This should only run after the typescript has been transpiled\n enforce: 'post',\n async transform(code: string, id: string) {\n if (!/\\.stories\\.(?:[tj]sx?|vue)$/.test(id) && !/(stories|story).mdx$/.test(id)) {\n return;\n }\n // TODO: Maybe convert `injectExportOrderPlugin` to function that returns object,\n // and run `await init;` once and then call `parse()` without `await`,\n // instead of calling `await parse()` every time.\n const [, exports] = await parse(code);\n\n if (exports.includes('__namedExportsOrder')) {\n // user has defined named exports already\n return;\n }\n const s = new MagicString(code);\n const orderedExports = exports.filter((e) => e !== 'default');\n s.append(`;export const __namedExportsOrder = ${JSON.stringify(orderedExports)};`);\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n },\n};\n"]}
|
|
@@ -10,7 +10,7 @@ function vueDocgen(vueVersion) {
|
|
|
10
10
|
return {
|
|
11
11
|
name: 'vue-docgen',
|
|
12
12
|
async transform(src, id) {
|
|
13
|
-
if (/\.(vue
|
|
13
|
+
if (/\.vue$/.test(id) && !/\.stories\.vue$/.test(id)) {
|
|
14
14
|
const metaData = await (0, vue_docgen_api_1.parse)(id);
|
|
15
15
|
const metaSource = JSON.stringify(metaData);
|
|
16
16
|
const s = new magic_string_1.default(src);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-docgen.js","sourceRoot":"","sources":["../../plugins/vue-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAuC;AAEvC,gEAAuC;AAEvC,SAAgB,SAAS,CAAC,UAAiB;IACzC,OAAO;QACL,IAAI,EAAE,YAAY;QAElB,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,IAAI,
|
|
1
|
+
{"version":3,"file":"vue-docgen.js","sourceRoot":"","sources":["../../plugins/vue-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAuC;AAEvC,gEAAuC;AAEvC,SAAgB,SAAS,CAAC,UAAiB;IACzC,OAAO;QACL,IAAI,EAAE,YAAY;QAElB,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACpD,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAK,EAAC,EAAE,CAAC,CAAC;gBACjC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAC5C,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;gBAC/B,MAAM,iBAAiB,GAAG,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,uBAAuB,CAAC;gBACnF,CAAC,CAAC,MAAM,CAAC,IAAI,iBAAiB,mBAAmB,UAAU,EAAE,CAAC,CAAC;gBAE/D,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;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAnBD,8BAmBC","sourcesContent":["import { parse } from 'vue-docgen-api';\nimport type { Plugin } from 'vite';\nimport MagicString from 'magic-string';\n\nexport function vueDocgen(vueVersion: 2 | 3): Plugin {\n return {\n name: 'vue-docgen',\n\n async transform(src: string, id: string) {\n if (/\\.vue$/.test(id) && !/\\.stories\\.vue$/.test(id)) {\n const metaData = await parse(id);\n const metaSource = JSON.stringify(metaData);\n const s = new MagicString(src);\n const componentLocation = vueVersion === 3 ? '_sfc_main' : '__component__.exports';\n s.append(`;${componentLocation}.__docgenInfo = ${metaSource}`);\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n }\n },\n };\n}\n"]}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.sourceLoaderPlugin = void 0;
|
|
7
7
|
const source_loader_1 = __importDefault(require("@storybook/source-loader"));
|
|
8
8
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
9
|
-
const storyPattern = /\.stories\.[jt]sx
|
|
9
|
+
const storyPattern = /\.stories\.(?:[jt]sx?|vue)$/;
|
|
10
10
|
const storySourcePattern = /var __STORY__ = "(.*)"/;
|
|
11
11
|
const storySourceReplacement = '--STORY_SOURCE_REPLACEMENT--';
|
|
12
12
|
const mockClassLoader = (id) => ({ emitWarning: (message) => console.warn(message), resourcePath: id });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-loader-plugin.js","sourceRoot":"","sources":["../source-loader-plugin.ts"],"names":[],"mappings":";;;;;;AACA,6EAA6D;AAE7D,gEAAuC;AAEvC,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"source-loader-plugin.js","sourceRoot":"","sources":["../source-loader-plugin.ts"],"names":[],"mappings":";;;;;;AACA,6EAA6D;AAE7D,gEAAuC;AAEvC,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AACpD,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAE9D,MAAM,eAAe,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;AAExH,+EAA+E;AAC/E,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,WAAmB,EAAE,EAAE;IACtE,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,SAAgB,kBAAkB,CAAC,MAAuB;IACxD,IAAI,MAAM,CAAC,UAAU,KAAK,aAAa,EAAE;QACvC,OAAO;YACL,IAAI,EAAE,qCAAqC;YAC3C,OAAO,EAAE,KAAK;YACd,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;gBACrC,IAAI,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;oBAC1B,MAAM,IAAI,GAAW,MAAM,uBAAqB,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;oBAChF,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CA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AC/B,iCAAiC;oBACjC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;oBAEjC,OAAO;wBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;wBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;qBACrB,CAAC;iBACH;YACH,CAAC;SACF;QACD;YACE,IAAI,EAAE,0CAA0C;YAChD,OAAO,EAAE,MAAM;YACf,UAAU;gBACR,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YACtC,CAAC;YACD,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;gBACrC,IAAI,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;oBAC1B,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;oBAC/B,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBACrC,MAAM,oBAAoB,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,GAAG,CAAC,EAAE,CAAC,CAAC;oBAC1C,8CAA8C;oBAC9C,IAAI,oBAAoB,EAAE;wBACxB,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,sBAAsB,EAAE,oBAAoB,CAAC,CAAC;wBAC9E,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;qBACrC;oBAED,OAAO;wBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;wBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;qBACrB,CAAC;iBACH;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AA/ED,gDA+EC","sourcesContent":["import type { Plugin } from 'vite';\nimport sourceLoaderTransform from '@storybook/source-loader';\nimport type { ExtendedOptions } from './types';\nimport MagicString from 'magic-string';\n\nconst storyPattern = /\\.stories\\.(?:[jt]sx?|vue)$/;\nconst storySourcePattern = /var __STORY__ = \"(.*)\"/;\nconst storySourceReplacement = '--STORY_SOURCE_REPLACEMENT--';\n\nconst mockClassLoader = (id: string) => ({ emitWarning: (message: string) => console.warn(message), resourcePath: id });\n\n// HACK: Until we can support only node 15+ and use string.prototype.replaceAll\nconst replaceAll = (str: string, search: string, replacement: string) => {\n return str.split(search).join(replacement);\n};\n\nexport function sourceLoaderPlugin(config: ExtendedOptions): Plugin | Plugin[] {\n if (config.configType === 'DEVELOPMENT') {\n return {\n name: 'storybook-vite-source-loader-plugin',\n enforce: 'pre',\n async transform(src: string, id: string) {\n if (id.match(storyPattern)) {\n const code: string = await sourceLoaderTransform.call(mockClassLoader(id), src);\n const s = new MagicString(src);\n // Entirely replace with new code\n s.overwrite(0, src.length, code);\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n }\n },\n };\n }\n\n // In production, we need to be fancier, to avoid vite:define plugin from replacing values inside the `__STORY__` string\n const storySources = new WeakMap<ExtendedOptions, Map<string, string>>();\n\n return [\n {\n name: 'storybook-vite-source-loader-plugin',\n enforce: 'pre',\n buildStart() {\n storySources.set(config, new Map());\n },\n async transform(src: string, id: string) {\n if (id.match(storyPattern)) {\n let code: string = await sourceLoaderTransform.call(mockClassLoader(id), src);\n const [_, sourceString] = code.match(storySourcePattern) ?? [null, null];\n if (sourceString) {\n const map = storySources.get(config);\n map?.set(id, sourceString);\n\n // Remove story source so that it is not processed by vite:define plugin\n code = replaceAll(code, sourceString, storySourceReplacement);\n }\n\n const s = new MagicString(src);\n // Entirely replace with new code\n s.overwrite(0, src.length, code);\n\n return {\n code: s.toString(),\n map: s.generateMap(),\n };\n }\n },\n },\n {\n name: 'storybook-vite-source-loader-plugin-post',\n enforce: 'post',\n buildStart() {\n storySources.set(config, new Map());\n },\n async transform(src: string, id: string) {\n if (id.match(storyPattern)) {\n const s = new MagicString(src);\n const map = storySources.get(config);\n const storySourceStatement = map?.get(id);\n // Put the previously-extracted source back in\n if (storySourceStatement) {\n const newCode = replaceAll(src, storySourceReplacement, storySourceStatement);\n s.overwrite(0, src.length, newCode);\n }\n\n return {\n code: s.toString(),\n map: s.generateMap(),\n };\n }\n },\n },\n ];\n}\n"]}
|
package/dist/vite-config.js
CHANGED
|
@@ -81,7 +81,7 @@ async function pluginConfig(options, _type) {
|
|
|
81
81
|
// We need the react plugin here to support MDX.
|
|
82
82
|
(0, plugin_react_1.default)({
|
|
83
83
|
// Do not treat story files as HMR boundaries, storybook itself needs to handle them.
|
|
84
|
-
exclude: [/\.stories\.([tj])
|
|
84
|
+
exclude: [/\.stories\.(?:[tj]sx?|vue)$/, /node_modules/].concat(framework === 'react' ? [] : [/\.([tj])sx?$/]),
|
|
85
85
|
}),
|
|
86
86
|
{
|
|
87
87
|
name: 'vite-plugin-storybook-allow',
|
package/dist/vite-config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6C;AAC7C,+DAAuC;AAEvC,iCAAuD;AACvD,mEAA8D;AAC9D,6EAAuE;AACvE,qDAAiD;AACjD,+CAA2C;AAC3C,iEAA4D;AAO5D,SAAgB,eAAe,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACzD,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC1D,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;AACz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AC5B,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;AA1MD,oCA0MC","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';\nimport semver from '@storybook/semver';\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(dir: string = process.cwd()): Record<string, any> | false {\n const packageJsonPath = path.resolve(dir, '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 const vuePath = framework === 'vue3' ? 'vue/dist/vue.esm-bundler.js' : 'vue/dist/vue.esm.js';\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve: /^vue3?$/.test(framework)\n ? {\n alias: {\n vue: vuePath,\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 const root = path.resolve(options.configDir, '..');\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\n if (framework === 'vue') {\n const pkgJson = readPackageJson(root);\n const vueVer: string | false | undefined = pkgJson && (pkgJson?.dependencies?.vue ?? pkgJson?.devDependencies?.vue);\n // Default to 2.7, but check if package.json has a version that is less than 2.7\n const is26 = vueVer && semver.gtr('2.7.0', vueVer);\n try {\n const vuePlugin = is26 ? require('vite-plugin-vue2').createVuePlugin : require('@vitejs/plugin-vue2');\n plugins.push(vuePlugin());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(`\n @storybook/builder-vite requires ${\n is26 ? 'vite-plugin-vue2' : '@vitejs/plugin-vue2'\n } to be installed when using @storybook/vue.\n Please install it and start storybook again.\n `);\n }\n throw err;\n }\n try {\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen(2));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires vue-docgen-api to be installed ' +\n 'when using @storybook/vue.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n\n if (framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\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 when using @storybook/vue3.\n Please install it and start storybook again.\n `);\n }\n throw err;\n }\n\n try {\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen(3));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires vue-docgen-api to be installed ' +\n 'when using @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\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 let typescriptPresent;\n\n try {\n require.resolve('typescript');\n typescriptPresent = true;\n } catch (e) {\n typescriptPresent = false;\n }\n\n if (reactDocgenOption === 'react-docgen-typescript' && typescriptPresent) {\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"]}
|
|
1
|
+
{"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6C;AAC7C,+DAAuC;AAEvC,iCAAuD;AACvD,mEAA8D;AAC9D,6EAAuE;AACvE,qDAAiD;AACjD,+CAA2C;AAC3C,iEAA4D;AAO5D,SAAgB,eAAe,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACzD,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC1D,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;IAC9B,MAAM,OAAO,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,qBAAqB,CAAC;IAE7F,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE,IAAI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AAc,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;AA1MD,oCA0MC","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';\nimport semver from '@storybook/semver';\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(dir: string = process.cwd()): Record<string, any> | false {\n const packageJsonPath = path.resolve(dir, '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 const vuePath = framework === 'vue3' ? 'vue/dist/vue.esm-bundler.js' : 'vue/dist/vue.esm.js';\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve: /^vue3?$/.test(framework)\n ? {\n alias: {\n vue: vuePath,\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 const root = path.resolve(options.configDir, '..');\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?|vue)$/, /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\n if (framework === 'vue') {\n const pkgJson = readPackageJson(root);\n const vueVer: string | false | undefined = pkgJson && (pkgJson?.dependencies?.vue ?? pkgJson?.devDependencies?.vue);\n // Default to 2.7, but check if package.json has a version that is less than 2.7\n const is26 = vueVer && semver.gtr('2.7.0', vueVer);\n try {\n const vuePlugin = is26 ? require('vite-plugin-vue2').createVuePlugin : require('@vitejs/plugin-vue2');\n plugins.push(vuePlugin());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(`\n @storybook/builder-vite requires ${\n is26 ? 'vite-plugin-vue2' : '@vitejs/plugin-vue2'\n } to be installed when using @storybook/vue.\n Please install it and start storybook again.\n `);\n }\n throw err;\n }\n try {\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen(2));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires vue-docgen-api to be installed ' +\n 'when using @storybook/vue.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n\n if (framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\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 when using @storybook/vue3.\n Please install it and start storybook again.\n `);\n }\n throw err;\n }\n\n try {\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen(3));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires vue-docgen-api to be installed ' +\n 'when using @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\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 let typescriptPresent;\n\n try {\n require.resolve('typescript');\n typescriptPresent = true;\n } catch (e) {\n typescriptPresent = false;\n }\n\n if (reactDocgenOption === 'react-docgen-typescript' && typescriptPresent) {\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"]}
|
|
@@ -6,7 +6,7 @@ export const injectExportOrderPlugin = {
|
|
|
6
6
|
// This should only run after the typescript has been transpiled
|
|
7
7
|
enforce: 'post',
|
|
8
8
|
async transform(code: string, id: string) {
|
|
9
|
-
if (!/\.stories\.([tj])
|
|
9
|
+
if (!/\.stories\.(?:[tj]sx?|vue)$/.test(id) && !/(stories|story).mdx$/.test(id)) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
// TODO: Maybe convert `injectExportOrderPlugin` to function that returns object,
|
package/package.json
CHANGED
package/plugins/vue-docgen.ts
CHANGED
|
@@ -7,7 +7,7 @@ export function vueDocgen(vueVersion: 2 | 3): Plugin {
|
|
|
7
7
|
name: 'vue-docgen',
|
|
8
8
|
|
|
9
9
|
async transform(src: string, id: string) {
|
|
10
|
-
if (/\.(vue
|
|
10
|
+
if (/\.vue$/.test(id) && !/\.stories\.vue$/.test(id)) {
|
|
11
11
|
const metaData = await parse(id);
|
|
12
12
|
const metaSource = JSON.stringify(metaData);
|
|
13
13
|
const s = new MagicString(src);
|
package/source-loader-plugin.ts
CHANGED
|
@@ -3,7 +3,7 @@ import sourceLoaderTransform from '@storybook/source-loader';
|
|
|
3
3
|
import type { ExtendedOptions } from './types';
|
|
4
4
|
import MagicString from 'magic-string';
|
|
5
5
|
|
|
6
|
-
const storyPattern = /\.stories\.[jt]sx
|
|
6
|
+
const storyPattern = /\.stories\.(?:[jt]sx?|vue)$/;
|
|
7
7
|
const storySourcePattern = /var __STORY__ = "(.*)"/;
|
|
8
8
|
const storySourceReplacement = '--STORY_SOURCE_REPLACEMENT--';
|
|
9
9
|
|
package/vite-config.ts
CHANGED
|
@@ -66,7 +66,7 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
66
66
|
// We need the react plugin here to support MDX.
|
|
67
67
|
viteReact({
|
|
68
68
|
// Do not treat story files as HMR boundaries, storybook itself needs to handle them.
|
|
69
|
-
exclude: [/\.stories\.([tj])
|
|
69
|
+
exclude: [/\.stories\.(?:[tj]sx?|vue)$/, /node_modules/].concat(framework === 'react' ? [] : [/\.([tj])sx?$/]),
|
|
70
70
|
}),
|
|
71
71
|
{
|
|
72
72
|
name: 'vite-plugin-storybook-allow',
|