@storybook/builder-vite 0.2.3 → 0.2.4
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/dist/vite-config.js +13 -5
- package/dist/vite-config.js.map +1 -1
- package/package.json +2 -8
- package/vite-config.ts +15 -6
package/dist/vite-config.js
CHANGED
|
@@ -101,16 +101,16 @@ async function pluginConfig(options, _type) {
|
|
|
101
101
|
if (framework === 'vue') {
|
|
102
102
|
const pkgJson = readPackageJson(root);
|
|
103
103
|
const vueVer = pkgJson && ((_b = (_a = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a.vue) !== null && _b !== void 0 ? _b : (_c = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.devDependencies) === null || _c === void 0 ? void 0 : _c.vue);
|
|
104
|
-
// Default to 2.7, but check
|
|
105
|
-
const
|
|
104
|
+
// Default to 2.7, but check if package.json has a version that is less than 2.7
|
|
105
|
+
const is26 = vueVer && semver_1.default.gtr('2.7.0', vueVer);
|
|
106
106
|
try {
|
|
107
|
-
const vuePlugin =
|
|
107
|
+
const vuePlugin = is26 ? require('vite-plugin-vue2').createVuePlugin : require('@vitejs/plugin-vue2');
|
|
108
108
|
plugins.push(vuePlugin());
|
|
109
109
|
}
|
|
110
110
|
catch (err) {
|
|
111
111
|
if (err.code === 'MODULE_NOT_FOUND') {
|
|
112
112
|
throw new Error(`
|
|
113
|
-
@storybook/builder-vite requires ${
|
|
113
|
+
@storybook/builder-vite requires ${is26 ? 'vite-plugin-vue2' : '@vitejs/plugin-vue2'} to be installed when using @storybook/vue.
|
|
114
114
|
Please install it and start storybook again.
|
|
115
115
|
`);
|
|
116
116
|
}
|
|
@@ -216,7 +216,15 @@ async function pluginConfig(options, _type) {
|
|
|
216
216
|
}
|
|
217
217
|
if (framework === 'react') {
|
|
218
218
|
const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply('typescript', {});
|
|
219
|
-
|
|
219
|
+
let typescriptPresent;
|
|
220
|
+
try {
|
|
221
|
+
require.resolve('typescript');
|
|
222
|
+
typescriptPresent = true;
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
typescriptPresent = false;
|
|
226
|
+
}
|
|
227
|
+
if (reactDocgenOption === 'react-docgen-typescript' && typescriptPresent) {
|
|
220
228
|
plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript')({
|
|
221
229
|
...reactDocgenTypescriptOptions,
|
|
222
230
|
// We *need* this set so that RDT returns default values in the same format as react-docgen
|
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;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,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AU,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;AAjMD,oCAiMC","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 = pkgJson && (pkgJson?.dependencies?.vue ?? pkgJson?.devDependencies?.vue);\n // Default to 2.7, but check it package.json has a version that isn't 2.7\n const is27 = !vueVer || semver.satisfies('2.7.0', vueVer);\n try {\n const vuePlugin = is27 ? require('@vitejs/plugin-vue2') : require('vite-plugin-vue2').createVuePlugin;\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 is27 ? '@vitejs/plugin-vue2' : 'vite-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 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"]}
|
|
1
|
+
{"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6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AE;QACzB,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAC1F,YAAY,EACZ,EAAsB,CACvB,CAAC;QAEF,IAAI,iBAAiB,CAAC;QAEtB,IAAI;YACF,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC9B,iBAAiB,GAAG,IAAI,CAAC;SAC1B;QAAC,OAAO,CAAC,EAAE;YACV,iBAAiB,GAAG,KAAK,CAAC;SAC3B;QAED,IAAI,iBAAiB,KAAK,yBAAyB,IAAI,iBAAiB,EAAE;YACxE,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;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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/builder-vite",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"sveltedoc-parser": "^4.2.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@preact/preset-vite": "^2.4.0",
|
|
45
44
|
"@storybook/addon-svelte-csf": "^2.0.7",
|
|
46
45
|
"@storybook/client-api": "^6.5.12",
|
|
47
46
|
"@storybook/mdx2-csf": "^0.0.3",
|
|
@@ -50,20 +49,15 @@
|
|
|
50
49
|
"@types/node": "^17.0.23",
|
|
51
50
|
"@typescript-eslint/eslint-plugin": "^5.38.0",
|
|
52
51
|
"@typescript-eslint/parser": "^5.38.0",
|
|
53
|
-
"@vitejs/plugin-vue": "^3.1.0",
|
|
54
|
-
"@vitejs/plugin-vue2": "^2.0.0",
|
|
55
52
|
"eslint": "^8.23.1",
|
|
56
53
|
"eslint-config-prettier": "^8.5.0",
|
|
57
54
|
"eslint-plugin-only-warn": "^1.0.3",
|
|
58
55
|
"eslint-plugin-storybook": "^0.6.4",
|
|
59
|
-
"preact": "^10.11.0",
|
|
60
56
|
"prettier": "^2.7.1",
|
|
61
57
|
"svelte": "^3.50.1",
|
|
62
58
|
"typescript": "^4.8.3",
|
|
63
59
|
"vite": "^3.1.0-beta.1",
|
|
64
|
-
"
|
|
65
|
-
"vue-docgen-api": "^4.40.0",
|
|
66
|
-
"vue-template-compiler": "^2.7.10"
|
|
60
|
+
"vue-docgen-api": "^4.40.0"
|
|
67
61
|
},
|
|
68
62
|
"peerDependencies": {
|
|
69
63
|
"@storybook/mdx2-csf": "^0.0.3",
|
package/vite-config.ts
CHANGED
|
@@ -85,17 +85,17 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
85
85
|
|
|
86
86
|
if (framework === 'vue') {
|
|
87
87
|
const pkgJson = readPackageJson(root);
|
|
88
|
-
const vueVer = pkgJson && (pkgJson?.dependencies?.vue ?? pkgJson?.devDependencies?.vue);
|
|
89
|
-
// Default to 2.7, but check
|
|
90
|
-
const
|
|
88
|
+
const vueVer: string | false | undefined = pkgJson && (pkgJson?.dependencies?.vue ?? pkgJson?.devDependencies?.vue);
|
|
89
|
+
// Default to 2.7, but check if package.json has a version that is less than 2.7
|
|
90
|
+
const is26 = vueVer && semver.gtr('2.7.0', vueVer);
|
|
91
91
|
try {
|
|
92
|
-
const vuePlugin =
|
|
92
|
+
const vuePlugin = is26 ? require('vite-plugin-vue2').createVuePlugin : require('@vitejs/plugin-vue2');
|
|
93
93
|
plugins.push(vuePlugin());
|
|
94
94
|
} catch (err) {
|
|
95
95
|
if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
|
|
96
96
|
throw new Error(`
|
|
97
97
|
@storybook/builder-vite requires ${
|
|
98
|
-
|
|
98
|
+
is26 ? 'vite-plugin-vue2' : '@vitejs/plugin-vue2'
|
|
99
99
|
} to be installed when using @storybook/vue.
|
|
100
100
|
Please install it and start storybook again.
|
|
101
101
|
`);
|
|
@@ -218,7 +218,16 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
218
218
|
{} as TypescriptConfig
|
|
219
219
|
);
|
|
220
220
|
|
|
221
|
-
|
|
221
|
+
let typescriptPresent;
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
require.resolve('typescript');
|
|
225
|
+
typescriptPresent = true;
|
|
226
|
+
} catch (e) {
|
|
227
|
+
typescriptPresent = false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (reactDocgenOption === 'react-docgen-typescript' && typescriptPresent) {
|
|
222
231
|
plugins.push(
|
|
223
232
|
require('@joshwooding/vite-plugin-react-docgen-typescript')({
|
|
224
233
|
...reactDocgenTypescriptOptions,
|