generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.ts
76 lines (69 loc) · 1.68 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { fileURLToPath } from 'url';
import { svelteIndexer, createIndex } from './indexer.js';
export function webpack(config) {
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.stories\.svelte$/,
enforce: 'post',
use: [
{
loader: fileURLToPath(new URL('../parser/svelte-stories-loader.js', import.meta.url))
.replace(/\\/g, "\\\\"), // For Windows paths
},
],
},
],
},
};
}
export async function viteFinal(config, options) {
const { plugins = [] } = config;
const svelteOptions = await options.presets.apply('svelteOptions', {}, options);
let svelteConfig = svelteOptions;
try {
const { loadSvelteConfig } = await import('@sveltejs/vite-plugin-svelte');
svelteConfig = { ...(await loadSvelteConfig()), ...svelteOptions };
} catch (err: any) {
const { log } = console;
if (err.code === 'MODULE_NOT_FOUND') {
log('@sveltejs/vite-plugin-svelte not found. Unable to load config from svelte.config file');
} else {
throw err;
}
}
const svelteCsfPlugin = (await import('../plugins/vite-svelte-csf.js')).default;
plugins.push(svelteCsfPlugin(svelteConfig));
return {
...config,
plugins,
};
}
/**
* Storybook < 7.4
*/
export const storyIndexers = async (indexers) => {
return [
{
test: /\.svelte$/,
indexer: svelteIndexer,
},
...(indexers || []),
];
};
/**
* Storybook >= 7.4
*/
export const experimental_indexers = (indexers) => {
return [
{
test: /\.svelte$/,
createIndex,
},
...(indexers || []),
];
}