@storybook/builder-vite 0.1.39 → 0.2.0-beta.0
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 +4 -3
- package/dist/vite-config.js.map +1 -1
- package/package.json +3 -3
- package/vite-config.ts +4 -3
package/dist/vite-config.js
CHANGED
|
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.pluginConfig = exports.commonConfig = exports.readPackageJson = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const fs_1 = __importDefault(require("fs"));
|
|
32
|
+
const vite_plugin_svelte_1 = require("@sveltejs/vite-plugin-svelte");
|
|
32
33
|
const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
|
|
33
34
|
const envs_1 = require("./envs");
|
|
34
35
|
const mock_core_js_1 = require("./mock-core-js");
|
|
@@ -130,10 +131,9 @@ async function pluginConfig(options, _type) {
|
|
|
130
131
|
// Non-story svelte files
|
|
131
132
|
// Starting in 1.0.0-next.42, svelte.config.js is included by default.
|
|
132
133
|
// We disable that, but allow it to be overridden in svelteOptions
|
|
133
|
-
plugins.push(sveltePlugin({
|
|
134
|
+
plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));
|
|
134
135
|
// Svelte stories without HMR
|
|
135
136
|
const storySveltePlugin = sveltePlugin({
|
|
136
|
-
configFile: false,
|
|
137
137
|
...svelteOptions,
|
|
138
138
|
exclude: userExclude,
|
|
139
139
|
include: storyPatterns,
|
|
@@ -155,7 +155,8 @@ async function pluginConfig(options, _type) {
|
|
|
155
155
|
}
|
|
156
156
|
try {
|
|
157
157
|
const csfPlugin = require('./svelte/csf-plugin').default;
|
|
158
|
-
|
|
158
|
+
const config = (0, vite_plugin_svelte_1.loadSvelteConfig)();
|
|
159
|
+
plugins.push(csfPlugin({ ...config, ...svelteOptions }));
|
|
159
160
|
}
|
|
160
161
|
catch (err) {
|
|
161
162
|
// Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.
|
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,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,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;QAC3C,QAAQ,EAAE,8BAA8B;QACxC,SAAS,EAAT,uBAAS;QACT,MAAM,EAAE,EAAE;QACV,OAAO,EACL,SAAS,KAAK,MAAM;YAClB,CAAC,CAAC;gBACE,KAAK,EAAE;oBACL,GAAG,EAAE,6BAA6B;iBACnC;aACF;YACH,CAAC,CAAC,EAAE;QACR,OAAO,EAAE,MAAM,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;KAC5C,CAAC;AACJ,CAAC;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AO,GAAG,eAAe,EAAE,CAAC;YAClC,iBAAiB,GAAG,OAAO,IAAI,CAAC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,0CAAE,UAAU,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,0CAAE,UAAU,CAAA,CAAC,CAAC;SAC5G;QAAC,OAAO,CAAC,EAAE;YACV,iBAAiB,GAAG,KAAK,CAAC;SAC3B;QAED,IAAI,WAAW,KAAK,yBAAyB,IAAI,iBAAiB,EAAE;YAClE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,kDAAkD,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC,CAAC;SACjH;aAAM,IAAI,WAAW,EAAE;YACtB,MAAM,EAAE,WAAW,EAAE,GAAG,wDAAa,wBAAwB,GAAC,CAAC;YAC/D,4DAA4D;YAC5D,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;SAChC;KACF;IAED,IAAI,SAAS,KAAK,UAAU,EAAE;QAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA1ID,oCA0IC","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({ configFile: false, ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));\n // Svelte stories without HMR\n const storySveltePlugin = sveltePlugin({\n configFile: false,\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 plugins.push(csfPlugin(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,qEAAgE;AAChE,wEAA6C;AAE7C,iCAAuD;AACvD,iDAA4C;AAC5C,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,OAA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AAC;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;AA1ID,oCA0IC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport { loadSvelteConfig } from '@sveltejs/vite-plugin-svelte';\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 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/builder-vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.0",
|
|
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",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@joshwooding/vite-plugin-react-docgen-typescript": "0.0.4",
|
|
17
17
|
"@storybook/mdx1-csf": "^0.0.4",
|
|
18
18
|
"@storybook/source-loader": "^6.4.3",
|
|
19
|
-
"@vitejs/plugin-react": "^
|
|
19
|
+
"@vitejs/plugin-react": "^2.0.0-beta.1",
|
|
20
20
|
"ast-types": "^0.14.2",
|
|
21
21
|
"es-module-lexer": "^0.9.3",
|
|
22
22
|
"glob": "^7.2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@storybook/mdx2-csf": "^0.0.3",
|
|
38
38
|
"@storybook/node-logger": ">=6.4.3 || >=6.5.0-alpha.0",
|
|
39
39
|
"@storybook/source-loader": ">=6.4.3 || >=6.5.0-alpha.0",
|
|
40
|
-
"vite": ">=
|
|
40
|
+
"vite": ">=3.0.0-alpha || >= 3.0.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"@storybook/mdx2-csf": {
|
package/vite-config.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as path from 'path';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { Plugin } from 'vite';
|
|
4
4
|
import { TypescriptConfig } from '@storybook/core-common';
|
|
5
|
+
import { loadSvelteConfig } from '@sveltejs/vite-plugin-svelte';
|
|
5
6
|
import viteReact from '@vitejs/plugin-react';
|
|
6
7
|
|
|
7
8
|
import { allowedEnvPrefix as envPrefix } from './envs';
|
|
@@ -119,10 +120,9 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
119
120
|
// Non-story svelte files
|
|
120
121
|
// Starting in 1.0.0-next.42, svelte.config.js is included by default.
|
|
121
122
|
// We disable that, but allow it to be overridden in svelteOptions
|
|
122
|
-
plugins.push(sveltePlugin({
|
|
123
|
+
plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));
|
|
123
124
|
// Svelte stories without HMR
|
|
124
125
|
const storySveltePlugin = sveltePlugin({
|
|
125
|
-
configFile: false,
|
|
126
126
|
...svelteOptions,
|
|
127
127
|
exclude: userExclude,
|
|
128
128
|
include: storyPatterns,
|
|
@@ -146,7 +146,8 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
|
|
|
146
146
|
|
|
147
147
|
try {
|
|
148
148
|
const csfPlugin = require('./svelte/csf-plugin').default;
|
|
149
|
-
|
|
149
|
+
const config = loadSvelteConfig();
|
|
150
|
+
plugins.push(csfPlugin({ ...config, ...svelteOptions }));
|
|
150
151
|
} catch (err) {
|
|
151
152
|
// Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.
|
|
152
153
|
// If it's any other kind of error, re-throw.
|