-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathmain.ts
91 lines (77 loc) · 2.75 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import type { StorybookConfig } from '@storybook/preact-vite';
import { mergeConfig } from 'vite';
import * as path from 'path';
import stylelint from 'vite-plugin-stylelint';
import generateEnvironmentVariables from '../config/environment-variables';
import { resolve } from 'node:path';
import preact from '@preact/preset-vite';
const certPath = process.env.CERT_PATH ?? path.resolve(__dirname, 'localhost.pem');
const certKeyPath = process.env.CERT_KEY_PATH ?? path.resolve(__dirname, 'localhost-key.pem');
const isHttps = process.env.IS_HTTPS === 'true';
const config: StorybookConfig = {
stories: ['../storybook/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
{
name: '@storybook/addon-essentials',
options: {
docs: false
}
},
{
name: '@storybook/addon-a11y'
}
],
framework: {
name: getAbsolutePath('@storybook/preact-vite'),
options: {}
},
// public added for msw: https://github.com/mswjs/msw-storybook-addon?tab=readme-ov-file#start-storybook
// '../storybook/public'
staticDirs: ['../storybook/assets', '../storybook/public'],
viteFinal(config) {
const finalConfig = mergeConfig(config, {
define: generateEnvironmentVariables(process.env.NODE_ENV),
resolve: {
alias: [
{
// this is required for the SCSS modules
find: /^~(.*)$/,
replacement: '$1'
},
{ find: /^styles(.*)$/, replacement: resolve(__dirname, '../src/styles') }
]
},
plugins: [preact(), stylelint({ emitErrorAsWarning: true })],
server: {
...(isHttps && {
https: {
key: certKeyPath,
cert: certPath
}
}),
watch: {
usePolling: true
},
proxy: {
'/api': {
target: `${isHttps ? 'https' : 'http'}://localhost:3030`,
secure: false
},
'/sdk': {
target: `${isHttps ? 'https' : 'http'}://localhost:3030`,
secure: false
}
}
}
});
return finalConfig;
}
};
export default config;
/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return path.dirname(require.resolve(path.join(value, 'package.json')));
}