forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreset.ts
More file actions
53 lines (45 loc) · 1.66 KB
/
preset.ts
File metadata and controls
53 lines (45 loc) · 1.66 KB
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
import { getProjectRoot, resolvePathInStorybookCache } from 'storybook/internal/common';
import type { PresetProperty } from 'storybook/internal/types';
import { getVirtualModules } from '@storybook/builder-webpack5';
import type { StorybookConfig } from './types';
export const addons: PresetProperty<'addons'> = [
import.meta.resolve('@storybook/ember/server/framework-preset-babel-ember'),
];
export const webpackFinal: StorybookConfig['webpackFinal'] = async (baseConfig, options) => {
const { virtualModules } = await getVirtualModules(options);
const babelOptions = await options.presets.apply('babel', {}, options);
const typescriptOptions = await options.presets.apply('typescript', {}, options);
return {
...baseConfig,
module: {
...baseConfig.module,
rules: [
...(baseConfig.module?.rules ?? []),
{
test: typescriptOptions.skipCompiler ? /\.((c|m)?jsx?)$/ : /\.((c|m)?(j|t)sx?)$/,
use: [
{
loader: import.meta.resolve('babel-loader'),
options: {
cacheDirectory: resolvePathInStorybookCache('babel'),
...babelOptions,
},
},
],
include: [getProjectRoot()],
exclude: [/node_modules/, ...Object.keys(virtualModules)],
},
],
},
};
};
export const core: PresetProperty<'core'> = async (config, options) => {
const framework = await options.presets.apply('framework');
return {
...config,
builder: {
name: import.meta.resolve('@storybook/builder-webpack5'),
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
};
};