2023-12-14 04:41:03 -05:00
|
|
|
import type { StorybookConfig } from '@storybook/react-webpack5'
|
|
|
|
import path from 'node:path'
|
2024-03-25 08:18:38 -04:00
|
|
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
2023-12-14 04:41:03 -05:00
|
|
|
|
|
|
|
const rootDir = path.resolve(__dirname, '..')
|
|
|
|
|
|
|
|
// NOTE: must be set before webpack config is imported
|
2024-02-06 04:34:15 -05:00
|
|
|
process.env.OVERLEAF_CONFIG = path.join(rootDir, 'config/settings.webpack.js')
|
2023-12-14 04:41:03 -05:00
|
|
|
|
2024-03-25 07:28:20 -04:00
|
|
|
function getAbsolutePath(value: string): any {
|
|
|
|
return path.dirname(require.resolve(path.join(value, 'package.json')))
|
|
|
|
}
|
|
|
|
|
2023-12-14 04:41:03 -05:00
|
|
|
const config: StorybookConfig = {
|
|
|
|
core: {
|
|
|
|
disableTelemetry: true,
|
|
|
|
},
|
|
|
|
staticDirs: [path.join(rootDir, 'public')],
|
|
|
|
stories: [
|
|
|
|
path.join(rootDir, 'frontend/stories/**/*.stories.{js,jsx,ts,tsx}'),
|
|
|
|
path.join(rootDir, 'modules/**/stories/**/*.stories.{js,jsx,ts,tsx}'),
|
|
|
|
],
|
|
|
|
addons: [
|
2024-03-25 07:28:20 -04:00
|
|
|
getAbsolutePath('@storybook/addon-links'),
|
|
|
|
getAbsolutePath('@storybook/addon-essentials'),
|
|
|
|
getAbsolutePath('@storybook/addon-interactions'),
|
|
|
|
getAbsolutePath('@storybook/addon-a11y'),
|
|
|
|
getAbsolutePath('@storybook/addon-webpack5-compiler-babel'),
|
2024-03-25 08:18:38 -04:00
|
|
|
{
|
|
|
|
name: getAbsolutePath('@storybook/addon-styling-webpack'),
|
|
|
|
options: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
{ loader: 'css-loader' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.less$/,
|
|
|
|
use: [
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
{ loader: 'css-loader' },
|
|
|
|
{ loader: 'less-loader' },
|
|
|
|
],
|
|
|
|
},
|
2024-10-23 03:33:56 -04:00
|
|
|
{
|
|
|
|
// Pass Sass files through sass-loader/css-loader/mini-css-extract-
|
|
|
|
// plugin (note: run in reverse order)
|
|
|
|
test: /\.s[ac]ss$/,
|
|
|
|
use: [
|
|
|
|
// Allows the CSS to be extracted to a separate .css file
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
// Resolves any CSS dependencies (e.g. url())
|
|
|
|
{ loader: 'css-loader' },
|
|
|
|
// Resolve relative paths sensibly in SASS
|
|
|
|
{ loader: 'resolve-url-loader' },
|
|
|
|
{
|
|
|
|
// Runs autoprefixer on CSS via postcss
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
postcssOptions: {
|
|
|
|
plugins: ['autoprefixer'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Compiles Sass to CSS
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: { sourceMap: true }, // sourceMap: true is required for resolve-url-loader
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2024-03-25 08:18:38 -04:00
|
|
|
],
|
|
|
|
plugins: [new MiniCssExtractPlugin()],
|
|
|
|
},
|
|
|
|
},
|
2023-12-14 04:41:03 -05:00
|
|
|
],
|
|
|
|
framework: {
|
2024-03-25 07:28:20 -04:00
|
|
|
name: getAbsolutePath('@storybook/react-webpack5'),
|
2023-12-14 04:41:03 -05:00
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
docs: {
|
|
|
|
autodocs: 'tag',
|
|
|
|
},
|
2024-03-25 07:28:20 -04:00
|
|
|
babel: (options: Record<string, any>) => {
|
2023-12-14 04:41:03 -05:00
|
|
|
return {
|
|
|
|
...options,
|
|
|
|
plugins: [
|
|
|
|
// ensure that TSX files are transformed before other plugins run
|
|
|
|
['@babel/plugin-transform-typescript', { isTSX: true }],
|
|
|
|
...(options.plugins ?? []),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
webpackFinal: storybookConfig => {
|
|
|
|
return {
|
|
|
|
...storybookConfig,
|
|
|
|
resolve: {
|
|
|
|
...storybookConfig.resolve,
|
|
|
|
fallback: {
|
|
|
|
...storybookConfig.resolve?.fallback,
|
|
|
|
fs: false,
|
|
|
|
os: false,
|
|
|
|
module: false,
|
2024-10-10 03:26:18 -04:00
|
|
|
tty: require.resolve('tty-browserify'),
|
2023-12-14 04:41:03 -05:00
|
|
|
},
|
|
|
|
extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.json'],
|
|
|
|
alias: {
|
|
|
|
...storybookConfig.resolve?.alias,
|
|
|
|
// custom prefixes for import paths
|
|
|
|
'@': path.join(rootDir, 'frontend/js/'),
|
|
|
|
},
|
|
|
|
},
|
2024-10-08 10:35:02 -04:00
|
|
|
module: {
|
|
|
|
...storybookConfig.module,
|
|
|
|
rules: (storybookConfig.module?.rules ?? []).concat({
|
|
|
|
test: /\.wasm$/,
|
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'js/[name]-[contenthash][ext]',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
2023-12-14 04:41:03 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
export default config
|