@storybook/builder-vite 0.2.0-beta.2 → 0.2.2
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 +1 -1
- package/codegen-iframe-script.ts +1 -0
- package/dist/codegen-iframe-script.js +1 -0
- package/dist/codegen-iframe-script.js.map +1 -1
- package/dist/inject-export-order-plugin.d.ts +1 -1
- package/dist/inject-export-order-plugin.js +8 -2
- package/dist/inject-export-order-plugin.js.map +1 -1
- package/dist/plugins/mdx-plugin.js +9 -3
- package/dist/plugins/mdx-plugin.js.map +1 -1
- package/dist/plugins/react-docgen.d.ts +1 -1
- package/dist/plugins/react-docgen.js +2 -2
- package/dist/plugins/react-docgen.js.map +1 -1
- package/dist/plugins/svelte-docgen.js +1 -1
- package/dist/plugins/svelte-docgen.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 +16 -11
- package/dist/source-loader-plugin.js.map +1 -1
- package/dist/svelte/csf-plugin.d.ts +1 -0
- package/dist/svelte/csf-plugin.js +10 -3
- package/dist/svelte/csf-plugin.js.map +1 -1
- package/dist/vite-config.js +16 -20
- package/dist/vite-config.js.map +1 -1
- package/dist/vite-server.js +1 -0
- package/dist/vite-server.js.map +1 -1
- package/inject-export-order-plugin.ts +5 -4
- package/package.json +8 -7
- package/plugins/mdx-plugin.ts +11 -3
- package/plugins/react-docgen.ts +5 -2
- package/plugins/svelte-docgen.ts +1 -1
- package/plugins/vue-docgen.ts +1 -1
- package/source-loader-plugin.ts +17 -10
- package/svelte/csf-plugin.ts +9 -3
- package/vite-config.ts +24 -19
- package/vite-server.ts +1 -0
- package/mock-core-js.ts +0 -17
package/README.md
CHANGED
package/codegen-iframe-script.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-iframe-script.js","sourceRoot":"","sources":["../codegen-iframe-script.ts"],"names":[],"mappings":";;;AAA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,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoEjG,CAAC,IAAI,EAAE,CAAC;IACX,OAAO,IAAI,CAAC;AACd,CAAC;AAzGD,4DAyGC","sourcesContent":["import { virtualPreviewFile, virtualStoriesFile } from './virtual-file-names';\nimport { transformAbsPath } from './utils/transform-abs-path';\nimport type { ExtendedOptions } from './types';\n\nexport async function generateIframeScriptCode(options: ExtendedOptions) {\n const { presets, frameworkPath, framework } = options;\n const frameworkImportPath = frameworkPath || `@storybook/${framework}`;\n\n const presetEntries = await presets.apply('config', [], options);\n const configEntries = [...presetEntries].filter(Boolean);\n\n const absoluteFilesToImport = (files: string[], name: string) =>\n files.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'${transformAbsPath(el)}'`).join('\\n');\n\n const importArray = (name: string, length: number) => new Array(length).fill(0).map((_, i) => `${name}_${i}`);\n\n // noinspection UnnecessaryLocalVariableJS\n /** @todo Inline variable and remove `noinspection` */\n // language=JavaScript\n const code = `\n // Ensure that the client API is initialized by the framework before any other iframe code\n // is loaded. That way our client-apis can assume the existence of the API+store\n import { configure } from '${frameworkImportPath}';\n\n import * as clientApi from \"@storybook/client-api\";\n import { logger } from '@storybook/client-logger';\n ${absoluteFilesToImport(configEntries, 'config')}\n import * as preview from '${virtualPreviewFile}';\n import { configStories } from '${virtualStoriesFile}';\n\n const {\n addDecorator,\n addParameters,\n addLoader,\n addArgTypesEnhancer,\n addArgsEnhancer,\n setGlobalRender,\n } = clientApi;\n\n const configs = [${importArray('config', configEntries.length).concat('preview.default').join(',')}].filter(Boolean)\n\n configs.forEach(config => {\n Object.keys(config).forEach((key) => {\n const value = config[key];\n switch (key) {\n case 'args': {\n if (typeof clientApi.addArgs !== \"undefined\") {\n return clientApi.addArgs(value);\n } else {\n return logger.warn(\n \"Could not add global args. Please open an issue in storybookjs/builder-vite.\"\n );\n }\n }\n case 'argTypes': {\n if (typeof clientApi.addArgTypes !== \"undefined\") {\n return clientApi.addArgTypes(value);\n } else {\n return logger.warn(\n \"Could not add global argTypes. Please open an issue in storybookjs/builder-vite.\"\n );\n }\n }\n case 'decorators': {\n return value.forEach((decorator) => addDecorator(decorator, false));\n }\n case 'loaders': {\n return value.forEach((loader) => addLoader(loader, false));\n }\n case 'parameters': {\n return addParameters({ ...value }, false);\n }\n case 'argTypesEnhancers': {\n return value.forEach((enhancer) => addArgTypesEnhancer(enhancer));\n }\n case 'argsEnhancers': {\n return value.forEach((enhancer) => addArgsEnhancer(enhancer))\n }\n case 'render': {\n return setGlobalRender(value)\n }\n case 'globals':\n case 'globalTypes': {\n const v = {};\n v[key] = value;\n return addParameters(v, false);\n }\n case 'decorateStory':\n case 'applyDecorators':\n case 'renderToDOM': {\n return null; // This key is not handled directly in v6 mode.\n }\n default: {\n // eslint-disable-next-line prefer-template\n return console.log(key + ' was not supported :( !');\n }\n }\n });\n })\n \n /* TODO: not quite sure what to do with this, to fix HMR\n if (import.meta.hot) {\n import.meta.hot.accept(); \n }\n */\n\n configStories(configure);\n `.trim();\n return code;\n}\n"]}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.injectExportOrderPlugin = void 0;
|
|
4
7
|
const es_module_lexer_1 = require("es-module-lexer");
|
|
8
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
5
9
|
exports.injectExportOrderPlugin = {
|
|
6
10
|
name: 'storybook-vite-inject-export-order-plugin',
|
|
7
11
|
// This should only run after the typescript has been transpiled
|
|
@@ -18,10 +22,12 @@ exports.injectExportOrderPlugin = {
|
|
|
18
22
|
// user has defined named exports already
|
|
19
23
|
return;
|
|
20
24
|
}
|
|
25
|
+
const s = new magic_string_1.default(code);
|
|
21
26
|
const orderedExports = exports.filter((e) => e !== 'default');
|
|
27
|
+
s.append(`;export const __namedExportsOrder = ${JSON.stringify(orderedExports)};`);
|
|
22
28
|
return {
|
|
23
|
-
code:
|
|
24
|
-
map:
|
|
29
|
+
code: s.toString(),
|
|
30
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
25
31
|
};
|
|
26
32
|
},
|
|
27
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-export-order-plugin.js","sourceRoot":"","sources":["../inject-export-order-plugin.ts"],"names":[],"mappings":"
|
|
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,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YACzE,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?$/.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"]}
|
|
@@ -64,15 +64,21 @@ function mdxPlugin(options) {
|
|
|
64
64
|
p.name === 'vite:react-jsx');
|
|
65
65
|
reactRefresh = reactRefreshPlugins.find((p) => p.transform);
|
|
66
66
|
},
|
|
67
|
-
async transform(
|
|
67
|
+
async transform(src, id, options) {
|
|
68
68
|
if (id.match(/\.mdx?$/)) {
|
|
69
69
|
// @ts-ignore
|
|
70
70
|
const { compile } = (features === null || features === void 0 ? void 0 : features.previewMdx2)
|
|
71
71
|
? await Promise.resolve().then(() => __importStar(require('@storybook/mdx2-csf')))
|
|
72
72
|
: await Promise.resolve().then(() => __importStar(require('@storybook/mdx1-csf')));
|
|
73
|
-
const mdxCode = String(await compile(
|
|
73
|
+
const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));
|
|
74
74
|
const modifiedCode = injectRenderer(mdxCode, Boolean(features === null || features === void 0 ? void 0 : features.previewMdx2));
|
|
75
|
-
|
|
75
|
+
const result = await (reactRefresh === null || reactRefresh === void 0 ? void 0 : reactRefresh.transform.call(this, modifiedCode, `${id}.jsx`, options));
|
|
76
|
+
if (!result)
|
|
77
|
+
return modifiedCode;
|
|
78
|
+
if (typeof result === 'string')
|
|
79
|
+
return result;
|
|
80
|
+
const { code, map: resultMap } = result;
|
|
81
|
+
return { code, map: !resultMap || typeof resultMap === 'string' ? resultMap : { ...resultMap, sources: [id] } };
|
|
76
82
|
}
|
|
77
83
|
},
|
|
78
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx-plugin.js","sourceRoot":"","sources":["../../plugins/mdx-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAE9F,SAAS,cAAc,CAAC,IAAY,EAAE,IAAa;IACjD,IAAI,IAAI,EAAE;QACR,OAAO;;aAEE,IAAI;YACL,CAAC;KACV;IAED,OAAO;;;;UAIC,IAAI;SACL,CAAC;AACV,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAC,OAAgB;IACxC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,IAAI,YAAgC,CAAC;IAErC,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,OAAO,EAAE,KAAK;QACd,cAAc,CAAC,EAAE,OAAO,EAAE;YACxB,0EAA0E;YAC1E,iHAAiH;YACjH,0DAA0D;YAC1D,gIAAgI;YAChI,MAAM,mBAAmB,GAAG,OAAO,CAAC,MAAM,CACxC,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C,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;aACjH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AA7CD,8BA6CC","sourcesContent":["import type { Options } from '@storybook/core-common';\nimport { Plugin } from 'vite';\n\nconst isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');\n\nfunction injectRenderer(code: string, mdx2: boolean) {\n if (mdx2) {\n return `\n import React from 'react';\n ${code}\n `;\n }\n\n return `\n /* @jsx mdx */\n import React from 'react';\n import { mdx } from '@mdx-js/react';\n ${code}\n `;\n}\n\n/**\n * Storybook uses two different loaders when dealing with MDX:\n *\n * - *stories.mdx and *story.mdx are compiled with the CSF compiler\n * - *.mdx are compiled with the MDX compiler directly\n *\n * @see https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-arbitrary-mdx\n */\nexport function mdxPlugin(options: Options): Plugin {\n const { features } = options;\n\n let reactRefresh: Plugin | undefined;\n\n return {\n name: 'storybook-vite-mdx-plugin',\n enforce: 'pre',\n configResolved({ plugins }) {\n // @vitejs/plugin-react-refresh has been upgraded to @vitejs/plugin-react,\n // and the name of the plugin performing `transform` has been changed from 'react-refresh' to 'vite:react-babel',\n // to be compatible, we need to look for both plugin name.\n // We should also look for the other plugins names exported from @vitejs/plugin-react in case there are some internal refactors.\n const reactRefreshPlugins = plugins.filter(\n (p) =>\n p.name === 'react-refresh' ||\n p.name === 'vite:react-babel' ||\n p.name === 'vite:react-refresh' ||\n p.name === 'vite:react-jsx'\n );\n reactRefresh = reactRefreshPlugins.find((p) => p.transform);\n },\n async transform(src, id, options) {\n if (id.match(/\\.mdx?$/)) {\n // @ts-ignore\n const { compile } = features?.previewMdx2\n ? await import('@storybook/mdx2-csf')\n : await import('@storybook/mdx1-csf');\n\n const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));\n\n const modifiedCode = injectRenderer(mdxCode, Boolean(features?.previewMdx2));\n\n const result = await reactRefresh?.transform!.call(this, modifiedCode, `${id}.jsx`, options);\n\n if (!result) return modifiedCode;\n\n if (typeof result === 'string') return result;\n\n const { code, map: resultMap } = result;\n\n return { code, map: !resultMap || typeof resultMap === 'string' ? resultMap : { ...resultMap, sources: [id] } };\n }\n },\n };\n}\n"]}
|
|
@@ -3,5 +3,5 @@ declare type Options = {
|
|
|
3
3
|
include?: string | RegExp | (string | RegExp)[];
|
|
4
4
|
exclude?: string | RegExp | (string | RegExp)[];
|
|
5
5
|
};
|
|
6
|
-
export declare function reactDocgen({ include, exclude }?: Options): Plugin;
|
|
6
|
+
export declare function reactDocgen({ include, exclude, }?: Options): Plugin;
|
|
7
7
|
export {};
|
|
@@ -14,7 +14,7 @@ const defaultHandlers = Object.values(react_docgen_1.handlers).map((handler) =>
|
|
|
14
14
|
const defaultResolver = react_docgen_1.resolver.findAllExportedComponentDefinitions;
|
|
15
15
|
const defaultImporter = react_docgen_1.importers.makeFsImporter();
|
|
16
16
|
const handlers = [...defaultHandlers, actualNameHandler_1.default];
|
|
17
|
-
function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules
|
|
17
|
+
function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules\/.*/, '**/**.stories.tsx'], } = {}) {
|
|
18
18
|
const cwd = process.cwd();
|
|
19
19
|
const filter = (0, pluginutils_1.createFilter)(include, exclude);
|
|
20
20
|
return {
|
|
@@ -37,7 +37,7 @@ function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules\
|
|
|
37
37
|
});
|
|
38
38
|
return {
|
|
39
39
|
code: s.toString(),
|
|
40
|
-
map: s.generateMap(),
|
|
40
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-docgen.js","sourceRoot":"","sources":["../../plugins/react-docgen.ts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AAK;QACd,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,MAAM,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;gBAAE,OAAO;YAE7B,IAAI;gBACF,yFAAyF;gBACzF,MAAM,aAAa,GAAG,IAAA,oBAAK,EAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC3F,CAAC;gBACb,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;gBAE/B,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;oBAC7B,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC;oBAC3C,IAAI,UAAU,EAAE;wBACd,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;wBAC3C,CAAC,CAAC,MAAM,CAAC,IAAI,UAAU,iBAAiB,OAAO,EAAE,CAAC,CAAC;qBACpD;gBACH,CAAC,CAAC,CAAC;gBAEH,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;oBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;iBAChD,CAAC;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,oFAAoF;gBACpF,qCAAqC;gBACrC,oBAAoB;aACrB;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAvCD,kCAuCC","sourcesContent":["import path from 'path';\nimport { createFilter } from '@rollup/pluginutils';\nimport {\n parse,\n handlers as docgenHandlers,\n resolver as docgenResolver,\n importers as docgenImporters,\n} from 'react-docgen';\nimport type { DocumentationObject } from 'react-docgen/lib/Documentation';\nimport MagicString from 'magic-string';\nimport type { Plugin } from 'vite';\nimport actualNameHandler from './docgen-handlers/actualNameHandler';\n\ntype DocObj = DocumentationObject & { actualName: string };\n\n// TODO: None of these are able to be overridden, so `default` is aspirational here.\nconst defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);\nconst defaultResolver = docgenResolver.findAllExportedComponentDefinitions;\nconst defaultImporter = docgenImporters.makeFsImporter();\nconst handlers = [...defaultHandlers, actualNameHandler];\n\ntype Options = {\n include?: string | RegExp | (string | RegExp)[];\n exclude?: string | RegExp | (string | RegExp)[];\n};\n\nexport function reactDocgen({\n include = /\\.(mjs|tsx?|jsx?)$/,\n exclude = [/node_modules\\/.*/, '**/**.stories.tsx'],\n}: Options = {}): Plugin {\n const cwd = process.cwd();\n const filter = createFilter(include, exclude);\n\n return {\n name: 'react-docgen',\n enforce: 'pre',\n async transform(src: string, id: string) {\n const relPath = path.relative(cwd, id);\n if (!filter(relPath)) return;\n\n try {\n // Since we're using `findAllExportedComponentDefinitions`, this will always be an array.\n const docgenResults = parse(src, defaultResolver, handlers, { importer: defaultImporter, filename: id }) as\n | DocObj[];\n const s = new MagicString(src);\n\n docgenResults.forEach((info) => {\n const { actualName, ...docgenInfo } = info;\n if (actualName) {\n const docNode = JSON.stringify(docgenInfo);\n s.append(`;${actualName}.__docgenInfo=${docNode}`);\n }\n });\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n } catch (e) {\n // Usually this is just an error from react-docgen that it couldn't find a component\n // Only uncomment for troubleshooting\n // console.error(e);\n }\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte-docgen.js","sourceRoot":"","sources":["../../plugins/svelte-docgen.ts"],"names":[],"mappings":";;;;;;AACA,gEAAuC;AACvC,gDAAwB;AACxB,4CAAoB;AACpB,wEAAyC;AAEzC,wDAAgD;AAChD,8CAA6C;AAE7C,0FAA0F;AAC1F,wGAAwG;AAExG,6IAA6I;AAC7I,sDAAsD;AACtD,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AAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBAErC,YAAY,CAAC,IAAI,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAExC,MAAM,aAAa,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;oBACpD,CAAC,CAAC,MAAM,CAAC,IAAI,aAAa,eAAe,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;iBAC1E;gBAAC,OAAO,KAAU,EAAE;oBACnB,IAAI,SAAS,EAAE;wBACb,oBAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;qBACrB;iBACF;gBAED,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;AArDD,oCAqDC","sourcesContent":["import type { Plugin } from 'vite';\nimport MagicString from 'magic-string';\nimport path from 'path';\nimport fs from 'fs';\nimport svelteDoc from 'sveltedoc-parser';\nimport type { SvelteParserOptions } from 'sveltedoc-parser';\nimport { logger } from '@storybook/node-logger';\nimport { preprocess } from 'svelte/compiler';\n\n// Most of the code here should probably be exported by @storybook/svelte and reused here.\n// See: https://github.com/storybookjs/storybook/blob/next/app/svelte/src/server/svelte-docgen-loader.ts\n\n// From https://github.com/sveltejs/svelte/blob/8db3e8d0297e052556f0b6dde310ef6e197b8d18/src/compiler/compile/utils/get_name_from_filename.ts\n// Copied because it is not exported from the compiler\nfunction getNameFromFilename(filename: string) {\n if (!filename) return null;\n\n const parts = filename.split(/[/\\\\]/).map(encodeURI);\n\n if (parts.length > 1) {\n const index_match = parts[parts.length - 1].match(/^index(\\.\\w+)/);\n if (index_match) {\n parts.pop();\n parts[parts.length - 1] += index_match[1];\n }\n }\n\n const base = parts\n .pop()\n ?.replace(/%/g, 'u')\n .replace(/\\.[^.]+$/, '')\n .replace(/[^a-zA-Z_$0-9]+/g, '_')\n .replace(/^_/, '')\n .replace(/_$/, '')\n .replace(/^(\\d)/, '_$1');\n\n if (!base) {\n throw new Error(`Could not derive component name from file ${filename}`);\n }\n\n return base[0].toUpperCase() + base.slice(1);\n}\n\nexport function svelteDocgen(svelteOptions: Record<string, any>): Plugin {\n const cwd = process.cwd();\n const { preprocess: preprocessOptions, logDocgen = false } = svelteOptions;\n\n return {\n name: 'svelte-docgen',\n async transform(src: string, id: string) {\n if (/\\.(svelte)$/.test(id)) {\n const resource = path.relative(cwd, id);\n\n let docOptions;\n if (preprocessOptions) {\n const src = fs.readFileSync(resource).toString();\n\n const { code: fileContent } = await preprocess(src, preprocessOptions, { filename: resource });\n\n docOptions = {\n fileContent,\n };\n } else {\n docOptions = { filename: resource };\n }\n\n // set SvelteDoc options\n const options: SvelteParserOptions = {\n ...docOptions,\n version: 3,\n };\n\n const s = new MagicString(src);\n\n try {\n const componentDoc = await svelteDoc.parse(options);\n // get filename for source content\n const file = path.basename(resource);\n\n componentDoc.name = path.basename(file);\n\n const componentName = getNameFromFilename(resource);\n s.append(`;${componentName}.__docgen = ${JSON.stringify(componentDoc)}`);\n } catch (error: any) {\n if (logDocgen) {\n logger.error(error);\n }\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n }\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-docgen.js","sourceRoot":"","sources":["../../plugins/vue-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAuC;AAEvC,gEAAuC;AAEvC,SAAgB,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,YAAY;QAElB,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACvB,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,CAAC,CAAC,MAAM,CAAC,6BAA6B,UAAU,EAAE,CAAC,CAAC;gBAEpD,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;oBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"vue-docgen.js","sourceRoot":"","sources":["../../plugins/vue-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAuC;AAEvC,gEAAuC;AAEvC,SAAgB,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,YAAY;QAElB,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACvB,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,CAAC,CAAC,MAAM,CAAC,6BAA6B,UAAU,EAAE,CAAC,CAAC;gBAEpD,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;AAlBD,8BAkBC","sourcesContent":["import { parse } from 'vue-docgen-api';\nimport type { Plugin } from 'vite';\nimport MagicString from 'magic-string';\n\nexport function vueDocgen(): Plugin {\n return {\n name: 'vue-docgen',\n\n async transform(src: string, id: string) {\n if (/\\.(vue)$/.test(id)) {\n const metaData = await parse(id);\n const metaSource = JSON.stringify(metaData);\n const s = new MagicString(src);\n s.append(`;_sfc_main.__docgenInfo = ${metaSource}`);\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n }\n },\n };\n}\n"]}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.sourceLoaderPlugin = void 0;
|
|
7
7
|
const source_loader_1 = __importDefault(require("@storybook/source-loader"));
|
|
8
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
8
9
|
const storyPattern = /\.stories\.[jt]sx?$/;
|
|
9
10
|
const storySourcePattern = /var __STORY__ = "(.*)"/;
|
|
10
11
|
const storySourceReplacement = '--STORY_SOURCE_REPLACEMENT--';
|
|
@@ -21,9 +22,12 @@ function sourceLoaderPlugin(config) {
|
|
|
21
22
|
async transform(src, id) {
|
|
22
23
|
if (id.match(storyPattern)) {
|
|
23
24
|
const code = await source_loader_1.default.call(mockClassLoader(id), src);
|
|
25
|
+
const s = new magic_string_1.default(src);
|
|
26
|
+
// Entirely replace with new code
|
|
27
|
+
s.overwrite(0, src.length, code);
|
|
24
28
|
return {
|
|
25
|
-
code,
|
|
26
|
-
map: {
|
|
29
|
+
code: s.toString(),
|
|
30
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
33
|
},
|
|
@@ -49,9 +53,12 @@ function sourceLoaderPlugin(config) {
|
|
|
49
53
|
// Remove story source so that it is not processed by vite:define plugin
|
|
50
54
|
code = replaceAll(code, sourceString, storySourceReplacement);
|
|
51
55
|
}
|
|
56
|
+
const s = new magic_string_1.default(src);
|
|
57
|
+
// Entirely replace with new code
|
|
58
|
+
s.overwrite(0, src.length, code);
|
|
52
59
|
return {
|
|
53
|
-
code,
|
|
54
|
-
map:
|
|
60
|
+
code: s.toString(),
|
|
61
|
+
map: s.generateMap(),
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
64
|
},
|
|
@@ -64,19 +71,17 @@ function sourceLoaderPlugin(config) {
|
|
|
64
71
|
},
|
|
65
72
|
async transform(src, id) {
|
|
66
73
|
if (id.match(storyPattern)) {
|
|
67
|
-
|
|
74
|
+
const s = new magic_string_1.default(src);
|
|
68
75
|
const map = storySources.get(config);
|
|
69
76
|
const storySourceStatement = map === null || map === void 0 ? void 0 : map.get(id);
|
|
70
77
|
// Put the previously-extracted source back in
|
|
71
78
|
if (storySourceStatement) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else {
|
|
75
|
-
code = src;
|
|
79
|
+
const newCode = replaceAll(src, storySourceReplacement, storySourceStatement);
|
|
80
|
+
s.overwrite(0, src.length, newCode);
|
|
76
81
|
}
|
|
77
82
|
return {
|
|
78
|
-
code,
|
|
79
|
-
map:
|
|
83
|
+
code: s.toString(),
|
|
84
|
+
map: s.generateMap(),
|
|
80
85
|
};
|
|
81
86
|
}
|
|
82
87
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-loader-plugin.js","sourceRoot":"","sources":["../source-loader-plugin.ts"],"names":[],"mappings":";;;;;;AACA,6EAA6D;
|
|
1
|
+
{"version":3,"file":"source-loader-plugin.js","sourceRoot":"","sources":["../source-loader-plugin.ts"],"names":[],"mappings":";;;;;;AACA,6EAA6D;AAE7D,gEAAuC;AAEvC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAC3C,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,M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AAG,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?$/;\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"]}
|
|
@@ -22,18 +22,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
const svelte_stories_loader_1 = require("@storybook/addon-svelte-csf/dist/cjs/parser/svelte-stories-loader");
|
|
27
30
|
const fs_1 = require("fs");
|
|
28
31
|
const extract_stories_1 = require("@storybook/addon-svelte-csf/dist/cjs/parser/extract-stories");
|
|
29
32
|
const parser = require.resolve('@storybook/addon-svelte-csf/dist/esm/parser/collect-stories').replace(/[/\\]/g, '/');
|
|
30
33
|
const svelte = __importStar(require("svelte/compiler"));
|
|
34
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
31
35
|
function csfPlugin(svelteOptions) {
|
|
32
36
|
return {
|
|
33
37
|
name: 'storybook-addon-svelte-csf',
|
|
34
38
|
enforce: 'post',
|
|
35
39
|
async transform(code, id) {
|
|
36
40
|
if (/\.stories\.svelte$/.test(id)) {
|
|
41
|
+
const s = new magic_string_1.default(code);
|
|
37
42
|
const component = (0, svelte_stories_loader_1.getNameFromFilename)(id);
|
|
38
43
|
let source = (0, fs_1.readFileSync)(id).toString();
|
|
39
44
|
if (svelteOptions && svelteOptions.preprocess) {
|
|
@@ -45,20 +50,22 @@ function csfPlugin(svelteOptions) {
|
|
|
45
50
|
.filter(([, def]) => !def.template)
|
|
46
51
|
.map(([id]) => `export const ${id} = __storiesMetaData.stories[${JSON.stringify(id)}];`)
|
|
47
52
|
.join('\n');
|
|
48
|
-
|
|
53
|
+
s.replace('export default', '// export default');
|
|
49
54
|
const namedExportsOrder = Object.entries(stories)
|
|
50
55
|
.filter(([, def]) => !def.template)
|
|
51
56
|
.map(([id]) => id);
|
|
52
57
|
const output = [
|
|
53
|
-
|
|
58
|
+
'',
|
|
54
59
|
`import parser from '${parser}';`,
|
|
55
60
|
`const __storiesMetaData = parser(${component}, ${JSON.stringify(all)});`,
|
|
56
61
|
'export default __storiesMetaData.meta;',
|
|
57
62
|
`export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`,
|
|
58
63
|
storyDef,
|
|
59
64
|
].join('\n');
|
|
65
|
+
s.append(output);
|
|
60
66
|
return {
|
|
61
|
-
code:
|
|
67
|
+
code: s.toString(),
|
|
68
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
62
69
|
};
|
|
63
70
|
}
|
|
64
71
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csf-plugin.js","sourceRoot":"","sources":["../../svelte/csf-plugin.ts"],"names":[],"mappings":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AE,CAAC,EAAE,EAAE,CAAC,gBAAgB,EAAE,gCAAgC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC;qBACvF,IAAI,CAAC,IAAI,CAAC,CAAC;gBAEd,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;gBAEjD,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,EAAE;oBACF,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;gBAEb,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEjB,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;AA3CD,4BA2CC","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';\nimport MagicString from 'magic-string';\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 s = new MagicString(code);\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 s.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 '',\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\n s.append(output);\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n }\n },\n };\n}\n"]}
|
package/dist/vite-config.js
CHANGED
|
@@ -31,7 +31,6 @@ const path = __importStar(require("path"));
|
|
|
31
31
|
const fs_1 = __importDefault(require("fs"));
|
|
32
32
|
const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
|
|
33
33
|
const envs_1 = require("./envs");
|
|
34
|
-
const mock_core_js_1 = require("./mock-core-js");
|
|
35
34
|
const code_generator_plugin_1 = require("./code-generator-plugin");
|
|
36
35
|
const inject_export_order_plugin_1 = require("./inject-export-order-plugin");
|
|
37
36
|
const mdx_plugin_1 = require("./plugins/mdx-plugin");
|
|
@@ -67,12 +66,10 @@ async function commonConfig(options, _type) {
|
|
|
67
66
|
}
|
|
68
67
|
exports.commonConfig = commonConfig;
|
|
69
68
|
async function pluginConfig(options, _type) {
|
|
70
|
-
var _a, _b;
|
|
71
69
|
const { framework, presets } = options;
|
|
72
70
|
const svelteOptions = await presets.apply('svelteOptions', {}, options);
|
|
73
71
|
const plugins = [
|
|
74
72
|
(0, code_generator_plugin_1.codeGeneratorPlugin)(options),
|
|
75
|
-
(0, mock_core_js_1.mockCoreJs)(),
|
|
76
73
|
(0, source_loader_plugin_1.sourceLoaderPlugin)(options),
|
|
77
74
|
(0, mdx_plugin_1.mdxPlugin)(options),
|
|
78
75
|
(0, no_fouc_1.noFouc)(),
|
|
@@ -152,11 +149,11 @@ async function pluginConfig(options, _type) {
|
|
|
152
149
|
}
|
|
153
150
|
throw err;
|
|
154
151
|
}
|
|
152
|
+
const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');
|
|
153
|
+
const config = { ...loadSvelteConfig(), ...svelteOptions };
|
|
155
154
|
try {
|
|
156
155
|
const csfPlugin = require('./svelte/csf-plugin').default;
|
|
157
|
-
|
|
158
|
-
const config = loadSvelteConfig();
|
|
159
|
-
plugins.push(csfPlugin({ ...config, ...svelteOptions }));
|
|
156
|
+
plugins.push(csfPlugin(config));
|
|
160
157
|
}
|
|
161
158
|
catch (err) {
|
|
162
159
|
// Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.
|
|
@@ -166,28 +163,27 @@ async function pluginConfig(options, _type) {
|
|
|
166
163
|
}
|
|
167
164
|
}
|
|
168
165
|
const { svelteDocgen } = await Promise.resolve().then(() => __importStar(require('./plugins/svelte-docgen')));
|
|
169
|
-
plugins.push(svelteDocgen(
|
|
166
|
+
plugins.push(svelteDocgen(config));
|
|
170
167
|
}
|
|
171
168
|
if (framework === 'preact') {
|
|
172
169
|
plugins.push(require('@preact/preset-vite').default());
|
|
173
170
|
}
|
|
174
171
|
if (framework === 'react') {
|
|
175
|
-
const { reactDocgen, reactDocgenTypescriptOptions } = await presets.apply('typescript', {});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
typescriptPresent = false;
|
|
183
|
-
}
|
|
184
|
-
if (reactDocgen === 'react-docgen-typescript' && typescriptPresent) {
|
|
185
|
-
plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript').default(reactDocgenTypescriptOptions));
|
|
172
|
+
const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply('typescript', {});
|
|
173
|
+
if (reactDocgenOption === 'react-docgen-typescript') {
|
|
174
|
+
plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript')({
|
|
175
|
+
...reactDocgenTypescriptOptions,
|
|
176
|
+
// We *need* this set so that RDT returns default values in the same format as react-docgen
|
|
177
|
+
savePropValueAsString: true,
|
|
178
|
+
}));
|
|
186
179
|
}
|
|
187
|
-
|
|
180
|
+
// Add react-docgen so long as the option is not false
|
|
181
|
+
if (typeof reactDocgenOption === 'string') {
|
|
188
182
|
const { reactDocgen } = await Promise.resolve().then(() => __importStar(require('./plugins/react-docgen')));
|
|
189
183
|
// Needs to run before the react plugin, so add to the front
|
|
190
|
-
plugins.unshift(
|
|
184
|
+
plugins.unshift(
|
|
185
|
+
// If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files
|
|
186
|
+
reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/ }));
|
|
191
187
|
}
|
|
192
188
|
}
|
|
193
189
|
if (framework === 'glimmerx') {
|
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;AAE7C,iCAAuD;AACvD,iDAA4C;AAC5C,mEAA8D;AAC9D,6EAAuE;AACvE,qDAAiD;AACjD,+CAA2C;AAC3C,iEAA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,KAAK,CAAC;SAC3B;QAED,IAAI,WAAW,KAAK,yBAAyB,IAAI,iBAAiB,EAAE;YAClE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,kDAAkD,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC,CAAC;SACjH;aAAM,IAAI,WAAW,EAAE;YACtB,MAAM,EAAE,WAAW,EAAE,GAAG,wDAAa,wBAAwB,GAAC,CAAC;YAC/D,4DAA4D;YAC5D,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;SAChC;KACF;IAED,IAAI,SAAS,KAAK,UAAU,EAAE;QAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA3ID,oCA2IC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport viteReact from '@vitejs/plugin-react';\n\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { mockCoreJs } from './mock-core-js';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './plugins/mdx-plugin';\nimport { noFouc } from './plugins/no-fouc';\nimport { sourceLoaderPlugin } from './source-loader-plugin';\n\nimport type { UserConfig } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport type PluginConfigType = 'build' | 'development';\n\nexport function readPackageJson(): Record<string, any> | false {\n const packageJsonPath = path.resolve('package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n return JSON.parse(jsonContent);\n}\n\n// Vite config that is common to development and production mode\nexport async function commonConfig(\n options: ExtendedOptions,\n _type: PluginConfigType\n): Promise<UserConfig & { configFile: false; root: string }> {\n const { framework } = options;\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve:\n framework === 'vue3'\n ? {\n alias: {\n vue: 'vue/dist/vue.esm-bundler.js',\n },\n }\n : {},\n plugins: await pluginConfig(options, _type),\n };\n}\n\nexport async function pluginConfig(options: ExtendedOptions, _type: PluginConfigType) {\n const { framework, presets } = options;\n const svelteOptions: Record<string, any> = await presets.apply('svelteOptions', {}, options);\n\n const plugins = [\n codeGeneratorPlugin(options),\n mockCoreJs(),\n sourceLoaderPlugin(options),\n mdxPlugin(options),\n noFouc(),\n injectExportOrderPlugin,\n // We need the react plugin here to support MDX.\n viteReact({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\\.([tj])sx?$/]),\n }),\n {\n name: 'vite-plugin-storybook-allow',\n enforce: 'post',\n config(config) {\n // if there is no allow list then Vite allows anything in the root directory\n // if there is an allow list then Vite allows anything in the listed directories\n // add the .storybook directory only if there's an allow list so that we don't end up\n // disallowing the root directory unless it's already disallowed\n if (config?.server?.fs?.allow) {\n config.server.fs.allow.push('.storybook');\n }\n },\n },\n ] as Plugin[];\n if (framework === 'vue' || framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @vitejs/plugin-vue to be installed ' +\n 'when using @storybook/vue or @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n if (framework === 'svelte') {\n try {\n const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;\n\n // We need to create two separate svelte plugins, one for stories, and one for other svelte files\n // because stories.svelte files cannot be hot-module-reloaded.\n // Suggested in: https://github.com/sveltejs/vite-plugin-svelte/issues/321#issuecomment-1113205509\n\n // First, create an array containing user exclude patterns, to combine with ours.\n const userExclude = Array.isArray(svelteOptions?.exclude)\n ? svelteOptions?.exclude\n : svelteOptions?.exclude\n ? [svelteOptions?.exclude]\n : [];\n\n // These are the svelte stories we need to exclude from HMR\n const storyPatterns = ['**/*.story.svelte', '**/*.stories.svelte'];\n // Non-story svelte files\n // Starting in 1.0.0-next.42, svelte.config.js is included by default.\n // We disable that, but allow it to be overridden in svelteOptions\n plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));\n // Svelte stories without HMR\n const storySveltePlugin = sveltePlugin({\n ...svelteOptions,\n exclude: userExclude,\n include: storyPatterns,\n hot: false,\n });\n plugins.push({\n // Starting in 1.0.0-next.43, the plugin function returns an array of plugins. We only want the first one here.\n ...(Array.isArray(storySveltePlugin) ? storySveltePlugin[0] : storySveltePlugin),\n name: 'vite-plugin-svelte-stories',\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @sveltejs/vite-plugin-svelte to be installed' +\n ' when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n\n try {\n const csfPlugin = require('./svelte/csf-plugin').default;\n const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');\n const config = loadSvelteConfig();\n plugins.push(csfPlugin({ ...config, ...svelteOptions }));\n } catch (err) {\n // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.\n // If it's any other kind of error, re-throw.\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n }\n\n const { svelteDocgen } = await import('./plugins/svelte-docgen');\n plugins.push(svelteDocgen(svelteOptions));\n }\n\n if (framework === 'preact') {\n plugins.push(require('@preact/preset-vite').default());\n }\n\n if (framework === 'react') {\n const { reactDocgen, reactDocgenTypescriptOptions } = await presets.apply('typescript', {} as TypescriptConfig);\n\n let typescriptPresent;\n\n try {\n const pkgJson = readPackageJson();\n typescriptPresent = pkgJson && (pkgJson?.devDependencies?.typescript || pkgJson?.dependencies?.typescript);\n } catch (e) {\n typescriptPresent = false;\n }\n\n if (reactDocgen === 'react-docgen-typescript' && typescriptPresent) {\n plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript').default(reactDocgenTypescriptOptions));\n } else if (reactDocgen) {\n const { reactDocgen } = await import('./plugins/react-docgen');\n // Needs to run before the react plugin, so add to the front\n plugins.unshift(reactDocgen());\n }\n }\n\n if (framework === 'glimmerx') {\n const plugin = require('vite-plugin-glimmerx/index.cjs');\n plugins.push(plugin.default());\n }\n\n return plugins;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6C;AAE7C,iCAAuD;AACvD,mEAA8D;AAC9D,6EAAuE;AACvE,qDAAiD;AACjD,+CAA2C;AAC3C,iEAA4D;AAO5D,SAAgB,eAAe;IAC7B,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACrD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;QACnC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,WAAW,GAAG,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC;AARD,0CAQC;AAED,gEAAgE;AACzD,KAAK,UAAU,YAAY,CAChC,OAAwB,EACxB,KAAuB;IAEvB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE,IAAI,CAAC,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B,GAAC,CAAC;QACjE,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;KACpC;IAED,IAAI,SAAS,KAAK,QAAQ,EAAE;QAC1B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KACxD;IAED,IAAI,SAAS,KAAK,OAAO,EAAE;QACzB,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAC1F,YAAY,EACZ,EAAsB,CACvB,CAAC;QAEF,IAAI,iBAAiB,KAAK,yBAAyB,EAAE;YACnD,OAAO,CAAC,IAAI,CACV,OAAO,CAAC,kDAAkD,CAAC,CAAC;gBAC1D,GAAG,4BAA4B;gBAC/B,2FAA2F;gBAC3F,qBAAqB,EAAE,IAAI;aAC5B,CAAC,CACH,CAAC;SACH;QAED,sDAAsD;QACtD,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACzC,MAAM,EAAE,WAAW,EAAE,GAAG,wDAAa,wBAAwB,GAAC,CAAC;YAC/D,4DAA4D;YAC5D,OAAO,CAAC,OAAO;YACb,sGAAsG;YACtG,WAAW,CAAC,EAAE,OAAO,EAAE,iBAAiB,KAAK,cAAc,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CACxG,CAAC;SACH;KACF;IAED,IAAI,SAAS,KAAK,UAAU,EAAE;QAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAjJD,oCAiJC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport viteReact from '@vitejs/plugin-react';\n\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './plugins/mdx-plugin';\nimport { noFouc } from './plugins/no-fouc';\nimport { sourceLoaderPlugin } from './source-loader-plugin';\n\nimport type { UserConfig } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport type PluginConfigType = 'build' | 'development';\n\nexport function readPackageJson(): Record<string, any> | false {\n const packageJsonPath = path.resolve('package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n return JSON.parse(jsonContent);\n}\n\n// Vite config that is common to development and production mode\nexport async function commonConfig(\n options: ExtendedOptions,\n _type: PluginConfigType\n): Promise<UserConfig & { configFile: false; root: string }> {\n const { framework } = options;\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve:\n framework === 'vue3'\n ? {\n alias: {\n vue: 'vue/dist/vue.esm-bundler.js',\n },\n }\n : {},\n plugins: await pluginConfig(options, _type),\n };\n}\n\nexport async function pluginConfig(options: ExtendedOptions, _type: PluginConfigType) {\n const { framework, presets } = options;\n const svelteOptions: Record<string, any> = await presets.apply('svelteOptions', {}, options);\n\n const plugins = [\n codeGeneratorPlugin(options),\n sourceLoaderPlugin(options),\n mdxPlugin(options),\n noFouc(),\n injectExportOrderPlugin,\n // We need the react plugin here to support MDX.\n viteReact({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\\.([tj])sx?$/]),\n }),\n {\n name: 'vite-plugin-storybook-allow',\n enforce: 'post',\n config(config) {\n // if there is no allow list then Vite allows anything in the root directory\n // if there is an allow list then Vite allows anything in the listed directories\n // add the .storybook directory only if there's an allow list so that we don't end up\n // disallowing the root directory unless it's already disallowed\n if (config?.server?.fs?.allow) {\n config.server.fs.allow.push('.storybook');\n }\n },\n },\n ] as Plugin[];\n if (framework === 'vue' || framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @vitejs/plugin-vue to be installed ' +\n 'when using @storybook/vue or @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n if (framework === 'svelte') {\n try {\n const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;\n\n // We need to create two separate svelte plugins, one for stories, and one for other svelte files\n // because stories.svelte files cannot be hot-module-reloaded.\n // Suggested in: https://github.com/sveltejs/vite-plugin-svelte/issues/321#issuecomment-1113205509\n\n // First, create an array containing user exclude patterns, to combine with ours.\n const userExclude = Array.isArray(svelteOptions?.exclude)\n ? svelteOptions?.exclude\n : svelteOptions?.exclude\n ? [svelteOptions?.exclude]\n : [];\n\n // These are the svelte stories we need to exclude from HMR\n const storyPatterns = ['**/*.story.svelte', '**/*.stories.svelte'];\n // Non-story svelte files\n // Starting in 1.0.0-next.42, svelte.config.js is included by default.\n // We disable that, but allow it to be overridden in svelteOptions\n plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));\n // Svelte stories without HMR\n const storySveltePlugin = sveltePlugin({\n ...svelteOptions,\n exclude: userExclude,\n include: storyPatterns,\n hot: false,\n });\n plugins.push({\n // Starting in 1.0.0-next.43, the plugin function returns an array of plugins. We only want the first one here.\n ...(Array.isArray(storySveltePlugin) ? storySveltePlugin[0] : storySveltePlugin),\n name: 'vite-plugin-svelte-stories',\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @sveltejs/vite-plugin-svelte to be installed' +\n ' when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n\n const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');\n const config = { ...loadSvelteConfig(), ...svelteOptions };\n\n try {\n const csfPlugin = require('./svelte/csf-plugin').default;\n plugins.push(csfPlugin(config));\n } catch (err) {\n // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.\n // If it's any other kind of error, re-throw.\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n }\n\n const { svelteDocgen } = await import('./plugins/svelte-docgen');\n plugins.push(svelteDocgen(config));\n }\n\n if (framework === 'preact') {\n plugins.push(require('@preact/preset-vite').default());\n }\n\n if (framework === 'react') {\n const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(\n 'typescript',\n {} as TypescriptConfig\n );\n\n if (reactDocgenOption === 'react-docgen-typescript') {\n plugins.push(\n require('@joshwooding/vite-plugin-react-docgen-typescript')({\n ...reactDocgenTypescriptOptions,\n // We *need* this set so that RDT returns default values in the same format as react-docgen\n savePropValueAsString: true,\n })\n );\n }\n\n // Add react-docgen so long as the option is not false\n if (typeof reactDocgenOption === 'string') {\n const { reactDocgen } = await import('./plugins/react-docgen');\n // Needs to run before the react plugin, so add to the front\n plugins.unshift(\n // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files\n reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\\.(mjs|tsx?|jsx?)$/ : /\\.(mjs|jsx?)$/ })\n );\n }\n }\n\n if (framework === 'glimmerx') {\n const plugin = require('vite-plugin-glimmerx/index.cjs');\n plugins.push(plugin.default());\n }\n\n return plugins;\n}\n"]}
|
package/dist/vite-server.js
CHANGED
|
@@ -20,6 +20,7 @@ async function createViteServer(options, devServer) {
|
|
|
20
20
|
strict: true,
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
|
+
appType: 'custom',
|
|
23
24
|
optimizeDeps: await (0, optimizeDeps_1.getOptimizeDeps)(baseConfig, options),
|
|
24
25
|
};
|
|
25
26
|
const finalConfig = await presets.apply('viteFinal', defaultConfig, options);
|
package/dist/vite-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-server.js","sourceRoot":"","sources":["../vite-server.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,iCAA8C;AAC9C,iDAAiD;AACjD,+CAA6C;AAKtC,KAAK,UAAU,gBAAgB,CAAC,OAAwB,EAAE,SAAiB;IAChF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAElC,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAY,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC9D,MAAM,aAAa,GAAG;QACpB,GAAG,UAAU;QACb,MAAM,EAAE;YACN,cAAc,EAAE,IAAI;YACpB,GAAG,EAAE;gBACH,IAAI;gBACJ,MAAM,EAAE,SAAS;aAClB;YACD,EAAE,EAAE;gBACF,MAAM,EAAE,IAAI;aACb;SACF;QACD,YAAY,EAAE,MAAM,IAAA,8BAAe,EAAC,UAAU,EAAE,OAAO,CAAC;KACzD,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAE7E,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAmB,KAAK,CAAC,CAAC;IAC7D,0EAA0E;IAC1E,MAAM,IAAI,GAAG,IAAA,2BAAoB,EAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAClE,kBAAkB;IAClB,WAAW,CAAC,MAAM,GAAG;QACnB,GAAG,WAAW,CAAC,MAAM;QACrB,GAAG,IAAI;KACR,CAAC;IAEF,OAAO,IAAA,mBAAY,EAAC,WAAW,CAAC,CAAC;AACnC,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-server.js","sourceRoot":"","sources":["../vite-server.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,iCAA8C;AAC9C,iDAAiD;AACjD,+CAA6C;AAKtC,KAAK,UAAU,gBAAgB,CAAC,OAAwB,EAAE,SAAiB;IAChF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAElC,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAY,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC9D,MAAM,aAAa,GAAG;QACpB,GAAG,UAAU;QACb,MAAM,EAAE;YACN,cAAc,EAAE,IAAI;YACpB,GAAG,EAAE;gBACH,IAAI;gBACJ,MAAM,EAAE,SAAS;aAClB;YACD,EAAE,EAAE;gBACF,MAAM,EAAE,IAAI;aACb;SACF;QACD,OAAO,EAAE,QAAiB;QAC1B,YAAY,EAAE,MAAM,IAAA,8BAAe,EAAC,UAAU,EAAE,OAAO,CAAC;KACzD,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAE7E,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAmB,KAAK,CAAC,CAAC;IAC7D,0EAA0E;IAC1E,MAAM,IAAI,GAAG,IAAA,2BAAoB,EAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAClE,kBAAkB;IAClB,WAAW,CAAC,MAAM,GAAG;QACnB,GAAG,WAAW,CAAC,MAAM;QACrB,GAAG,IAAI;KACR,CAAC;IAEF,OAAO,IAAA,mBAAY,EAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AAhCD,4CAgCC","sourcesContent":["import { createServer } from 'vite';\nimport { stringifyProcessEnvs } from './envs';\nimport { getOptimizeDeps } from './optimizeDeps';\nimport { commonConfig } from './vite-config';\n\nimport type { Server } from 'http';\nimport type { EnvsRaw, ExtendedOptions } from './types';\n\nexport async function createViteServer(options: ExtendedOptions, devServer: Server) {\n const { port, presets } = options;\n\n const baseConfig = await commonConfig(options, 'development');\n const defaultConfig = {\n ...baseConfig,\n server: {\n middlewareMode: true,\n hmr: {\n port,\n server: devServer,\n },\n fs: {\n strict: true,\n },\n },\n appType: 'custom' as const,\n optimizeDeps: await getOptimizeDeps(baseConfig, options),\n };\n\n const finalConfig = await presets.apply('viteFinal', defaultConfig, options);\n\n const envsRaw = await presets.apply<Promise<EnvsRaw>>('env');\n // Stringify env variables after getting `envPrefix` from the final config\n const envs = stringifyProcessEnvs(envsRaw, finalConfig.envPrefix);\n // Update `define`\n finalConfig.define = {\n ...finalConfig.define,\n ...envs,\n };\n\n return createServer(finalConfig);\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parse } from 'es-module-lexer';
|
|
2
|
+
import MagicString from 'magic-string';
|
|
2
3
|
|
|
3
4
|
export const injectExportOrderPlugin = {
|
|
4
5
|
name: 'storybook-vite-inject-export-order-plugin',
|
|
@@ -17,12 +18,12 @@ export const injectExportOrderPlugin = {
|
|
|
17
18
|
// user has defined named exports already
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
const s = new MagicString(code);
|
|
21
22
|
const orderedExports = exports.filter((e) => e !== 'default');
|
|
22
|
-
|
|
23
|
+
s.append(`;export const __namedExportsOrder = ${JSON.stringify(orderedExports)};`);
|
|
23
24
|
return {
|
|
24
|
-
code:
|
|
25
|
-
map:
|
|
25
|
+
code: s.toString(),
|
|
26
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
26
27
|
};
|
|
27
28
|
},
|
|
28
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/builder-vite",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A plugin to run and build Storybooks with Vite",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,10 +13,13 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/storybookjs/builder-vite/#readme",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@joshwooding/vite-plugin-react-docgen-typescript": "0.0.
|
|
16
|
+
"@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
|
|
17
|
+
"@rollup/pluginutils": "^4.2.1",
|
|
18
|
+
"@storybook/core-common": "^6.4.3",
|
|
17
19
|
"@storybook/mdx1-csf": "^0.0.4",
|
|
20
|
+
"@storybook/node-logger": "^6.4.3",
|
|
18
21
|
"@storybook/source-loader": "^6.4.3",
|
|
19
|
-
"@vitejs/plugin-react": "^2.0.0
|
|
22
|
+
"@vitejs/plugin-react": "^2.0.0",
|
|
20
23
|
"ast-types": "^0.14.2",
|
|
21
24
|
"es-module-lexer": "^0.9.3",
|
|
22
25
|
"glob": "^7.2.0",
|
|
@@ -28,16 +31,14 @@
|
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@storybook/mdx2-csf": "^0.0.3",
|
|
34
|
+
"@sveltejs/vite-plugin-svelte": "^1.0.0",
|
|
31
35
|
"@types/express": "^4.17.13",
|
|
32
36
|
"@types/node": "^17.0.23",
|
|
33
37
|
"vue-docgen-api": "^4.40.0"
|
|
34
38
|
},
|
|
35
39
|
"peerDependencies": {
|
|
36
|
-
"@storybook/core-common": ">=6.4.3 || >=6.5.0-alpha.0",
|
|
37
40
|
"@storybook/mdx2-csf": "^0.0.3",
|
|
38
|
-
"
|
|
39
|
-
"@storybook/source-loader": ">=6.4.3 || >=6.5.0-alpha.0",
|
|
40
|
-
"vite": ">=3.0.0-alpha || >= 3.0.0"
|
|
41
|
+
"vite": ">= 3.0.0"
|
|
41
42
|
},
|
|
42
43
|
"peerDependenciesMeta": {
|
|
43
44
|
"@storybook/mdx2-csf": {
|
package/plugins/mdx-plugin.ts
CHANGED
|
@@ -49,18 +49,26 @@ export function mdxPlugin(options: Options): Plugin {
|
|
|
49
49
|
);
|
|
50
50
|
reactRefresh = reactRefreshPlugins.find((p) => p.transform);
|
|
51
51
|
},
|
|
52
|
-
async transform(
|
|
52
|
+
async transform(src, id, options) {
|
|
53
53
|
if (id.match(/\.mdx?$/)) {
|
|
54
54
|
// @ts-ignore
|
|
55
55
|
const { compile } = features?.previewMdx2
|
|
56
56
|
? await import('@storybook/mdx2-csf')
|
|
57
57
|
: await import('@storybook/mdx1-csf');
|
|
58
58
|
|
|
59
|
-
const mdxCode = String(await compile(
|
|
59
|
+
const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));
|
|
60
60
|
|
|
61
61
|
const modifiedCode = injectRenderer(mdxCode, Boolean(features?.previewMdx2));
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
const result = await reactRefresh?.transform!.call(this, modifiedCode, `${id}.jsx`, options);
|
|
64
|
+
|
|
65
|
+
if (!result) return modifiedCode;
|
|
66
|
+
|
|
67
|
+
if (typeof result === 'string') return result;
|
|
68
|
+
|
|
69
|
+
const { code, map: resultMap } = result;
|
|
70
|
+
|
|
71
|
+
return { code, map: !resultMap || typeof resultMap === 'string' ? resultMap : { ...resultMap, sources: [id] } };
|
|
64
72
|
}
|
|
65
73
|
},
|
|
66
74
|
};
|
package/plugins/react-docgen.ts
CHANGED
|
@@ -24,7 +24,10 @@ type Options = {
|
|
|
24
24
|
exclude?: string | RegExp | (string | RegExp)[];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export function reactDocgen({
|
|
27
|
+
export function reactDocgen({
|
|
28
|
+
include = /\.(mjs|tsx?|jsx?)$/,
|
|
29
|
+
exclude = [/node_modules\/.*/, '**/**.stories.tsx'],
|
|
30
|
+
}: Options = {}): Plugin {
|
|
28
31
|
const cwd = process.cwd();
|
|
29
32
|
const filter = createFilter(include, exclude);
|
|
30
33
|
|
|
@@ -51,7 +54,7 @@ export function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_m
|
|
|
51
54
|
|
|
52
55
|
return {
|
|
53
56
|
code: s.toString(),
|
|
54
|
-
map: s.generateMap(),
|
|
57
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
55
58
|
};
|
|
56
59
|
} catch (e) {
|
|
57
60
|
// Usually this is just an error from react-docgen that it couldn't find a component
|
package/plugins/svelte-docgen.ts
CHANGED
package/plugins/vue-docgen.ts
CHANGED
package/source-loader-plugin.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
import sourceLoaderTransform from '@storybook/source-loader';
|
|
3
3
|
import type { ExtendedOptions } from './types';
|
|
4
|
+
import MagicString from 'magic-string';
|
|
4
5
|
|
|
5
6
|
const storyPattern = /\.stories\.[jt]sx?$/;
|
|
6
7
|
const storySourcePattern = /var __STORY__ = "(.*)"/;
|
|
@@ -21,10 +22,13 @@ export function sourceLoaderPlugin(config: ExtendedOptions): Plugin | Plugin[] {
|
|
|
21
22
|
async transform(src: string, id: string) {
|
|
22
23
|
if (id.match(storyPattern)) {
|
|
23
24
|
const code: string = await sourceLoaderTransform.call(mockClassLoader(id), src);
|
|
25
|
+
const s = new MagicString(src);
|
|
26
|
+
// Entirely replace with new code
|
|
27
|
+
s.overwrite(0, src.length, code);
|
|
24
28
|
|
|
25
29
|
return {
|
|
26
|
-
code,
|
|
27
|
-
map: {
|
|
30
|
+
code: s.toString(),
|
|
31
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
34
|
},
|
|
@@ -53,9 +57,13 @@ export function sourceLoaderPlugin(config: ExtendedOptions): Plugin | Plugin[] {
|
|
|
53
57
|
code = replaceAll(code, sourceString, storySourceReplacement);
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
const s = new MagicString(src);
|
|
61
|
+
// Entirely replace with new code
|
|
62
|
+
s.overwrite(0, src.length, code);
|
|
63
|
+
|
|
56
64
|
return {
|
|
57
|
-
code,
|
|
58
|
-
map:
|
|
65
|
+
code: s.toString(),
|
|
66
|
+
map: s.generateMap(),
|
|
59
67
|
};
|
|
60
68
|
}
|
|
61
69
|
},
|
|
@@ -68,19 +76,18 @@ export function sourceLoaderPlugin(config: ExtendedOptions): Plugin | Plugin[] {
|
|
|
68
76
|
},
|
|
69
77
|
async transform(src: string, id: string) {
|
|
70
78
|
if (id.match(storyPattern)) {
|
|
71
|
-
|
|
79
|
+
const s = new MagicString(src);
|
|
72
80
|
const map = storySources.get(config);
|
|
73
81
|
const storySourceStatement = map?.get(id);
|
|
74
82
|
// Put the previously-extracted source back in
|
|
75
83
|
if (storySourceStatement) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
code = src;
|
|
84
|
+
const newCode = replaceAll(src, storySourceReplacement, storySourceStatement);
|
|
85
|
+
s.overwrite(0, src.length, newCode);
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
return {
|
|
82
|
-
code,
|
|
83
|
-
map:
|
|
89
|
+
code: s.toString(),
|
|
90
|
+
map: s.generateMap(),
|
|
84
91
|
};
|
|
85
92
|
}
|
|
86
93
|
},
|
package/svelte/csf-plugin.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { extractStories } from '@storybook/addon-svelte-csf/dist/cjs/parser/extr
|
|
|
4
4
|
const parser = require.resolve('@storybook/addon-svelte-csf/dist/esm/parser/collect-stories').replace(/[/\\]/g, '/');
|
|
5
5
|
import type { Options } from '@sveltejs/vite-plugin-svelte';
|
|
6
6
|
import * as svelte from 'svelte/compiler';
|
|
7
|
+
import MagicString from 'magic-string';
|
|
7
8
|
|
|
8
9
|
export default function csfPlugin(svelteOptions?: Options) {
|
|
9
10
|
return {
|
|
@@ -11,6 +12,7 @@ export default function csfPlugin(svelteOptions?: Options) {
|
|
|
11
12
|
enforce: 'post',
|
|
12
13
|
async transform(code: string, id: string) {
|
|
13
14
|
if (/\.stories\.svelte$/.test(id)) {
|
|
15
|
+
const s = new MagicString(code);
|
|
14
16
|
const component = getNameFromFilename(id);
|
|
15
17
|
let source = readFileSync(id).toString();
|
|
16
18
|
if (svelteOptions && svelteOptions.preprocess) {
|
|
@@ -23,22 +25,26 @@ export default function csfPlugin(svelteOptions?: Options) {
|
|
|
23
25
|
.map(([id]) => `export const ${id} = __storiesMetaData.stories[${JSON.stringify(id)}];`)
|
|
24
26
|
.join('\n');
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
s.replace('export default', '// export default');
|
|
27
29
|
|
|
28
30
|
const namedExportsOrder = Object.entries<any>(stories)
|
|
29
31
|
.filter(([, def]) => !def.template)
|
|
30
32
|
.map(([id]) => id);
|
|
31
33
|
|
|
32
34
|
const output = [
|
|
33
|
-
|
|
35
|
+
'',
|
|
34
36
|
`import parser from '${parser}';`,
|
|
35
37
|
`const __storiesMetaData = parser(${component}, ${JSON.stringify(all)});`,
|
|
36
38
|
'export default __storiesMetaData.meta;',
|
|
37
39
|
`export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`,
|
|
38
40
|
storyDef,
|
|
39
41
|
].join('\n');
|
|
42
|
+
|
|
43
|
+
s.append(output);
|
|
44
|
+
|
|
40
45
|
return {
|
|
41
|
-
code:
|
|
46
|
+
code: s.toString(),
|
|
47
|
+
map: s.generateMap({ hires: true, source: id }),
|
|
42
48
|
};
|
|
43
49
|
}
|
|
44
50
|
},
|
package/vite-config.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { TypescriptConfig } from '@storybook/core-common';
|
|
|
5
5
|
import viteReact from '@vitejs/plugin-react';
|
|
6
6
|
|
|
7
7
|
import { allowedEnvPrefix as envPrefix } from './envs';
|
|
8
|
-
import { mockCoreJs } from './mock-core-js';
|
|
9
8
|
import { codeGeneratorPlugin } from './code-generator-plugin';
|
|
10
9
|
import { injectExportOrderPlugin } from './inject-export-order-plugin';
|
|
11
10
|
import { mdxPlugin } from './plugins/mdx-plugin';
|
|
@@ -58,7 +57,6 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
58
57
|
|
|
59
58
|
const plugins = [
|
|
60
59
|
codeGeneratorPlugin(options),
|
|
61
|
-
mockCoreJs(),
|
|
62
60
|
sourceLoaderPlugin(options),
|
|
63
61
|
mdxPlugin(options),
|
|
64
62
|
noFouc(),
|
|
@@ -143,11 +141,12 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
143
141
|
throw err;
|
|
144
142
|
}
|
|
145
143
|
|
|
144
|
+
const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');
|
|
145
|
+
const config = { ...loadSvelteConfig(), ...svelteOptions };
|
|
146
|
+
|
|
146
147
|
try {
|
|
147
148
|
const csfPlugin = require('./svelte/csf-plugin').default;
|
|
148
|
-
|
|
149
|
-
const config = loadSvelteConfig();
|
|
150
|
-
plugins.push(csfPlugin({ ...config, ...svelteOptions }));
|
|
149
|
+
plugins.push(csfPlugin(config));
|
|
151
150
|
} catch (err) {
|
|
152
151
|
// Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.
|
|
153
152
|
// If it's any other kind of error, re-throw.
|
|
@@ -157,7 +156,7 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
157
156
|
}
|
|
158
157
|
|
|
159
158
|
const { svelteDocgen } = await import('./plugins/svelte-docgen');
|
|
160
|
-
plugins.push(svelteDocgen(
|
|
159
|
+
plugins.push(svelteDocgen(config));
|
|
161
160
|
}
|
|
162
161
|
|
|
163
162
|
if (framework === 'preact') {
|
|
@@ -165,23 +164,29 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
if (framework === 'react') {
|
|
168
|
-
const { reactDocgen, reactDocgenTypescriptOptions } = await presets.apply(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
167
|
+
const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(
|
|
168
|
+
'typescript',
|
|
169
|
+
{} as TypescriptConfig
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
if (reactDocgenOption === 'react-docgen-typescript') {
|
|
173
|
+
plugins.push(
|
|
174
|
+
require('@joshwooding/vite-plugin-react-docgen-typescript')({
|
|
175
|
+
...reactDocgenTypescriptOptions,
|
|
176
|
+
// We *need* this set so that RDT returns default values in the same format as react-docgen
|
|
177
|
+
savePropValueAsString: true,
|
|
178
|
+
})
|
|
179
|
+
);
|
|
177
180
|
}
|
|
178
181
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
} else if (reactDocgen) {
|
|
182
|
+
// Add react-docgen so long as the option is not false
|
|
183
|
+
if (typeof reactDocgenOption === 'string') {
|
|
182
184
|
const { reactDocgen } = await import('./plugins/react-docgen');
|
|
183
185
|
// Needs to run before the react plugin, so add to the front
|
|
184
|
-
plugins.unshift(
|
|
186
|
+
plugins.unshift(
|
|
187
|
+
// If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files
|
|
188
|
+
reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/ })
|
|
189
|
+
);
|
|
185
190
|
}
|
|
186
191
|
}
|
|
187
192
|
|
package/vite-server.ts
CHANGED
package/mock-core-js.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function mockCoreJs() {
|
|
2
|
-
return {
|
|
3
|
-
name: 'mock-core-js',
|
|
4
|
-
resolveId(id: string) {
|
|
5
|
-
if (id.includes('node_modules/core-js')) {
|
|
6
|
-
return id;
|
|
7
|
-
}
|
|
8
|
-
return undefined;
|
|
9
|
-
},
|
|
10
|
-
load(id: string) {
|
|
11
|
-
if (id.includes('node_modules/core-js')) {
|
|
12
|
-
return '';
|
|
13
|
-
}
|
|
14
|
-
return undefined;
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|