Description
We are migrating from vite, and we are blocked by an incompatibility with https://github.com/gebeto/storybook-addon-manual-mocks
which was working perfectly with vite.
You can see the issue we ran into here : gebeto/storybook-addon-manual-mocks#19
There's also a version of this preset for webpack so we tried to use webpack addon but the error was the same.
Finally we tried to mimic the code of the addon here : https://github.com/gebeto/storybook-addon-manual-mocks/blob/main/webpack/preset.js
by overriding the rsbuild config in storybook/main.ts like that :
import { StorybookConfig } from 'storybook-react-rsbuild'
import { mergeRsbuildConfig, rspack } from '@rsbuild/core'
import path from 'path'
import fs from 'fs'
const EXTENSIONS = [".ts", ".js"]
const MOCKS_DIRECTORY = "mocks"
const config: StorybookConfig = {
stories: [
"../src/**/*.stories.@(ts|tsx)"
],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
'storybook-addon-remix-react-router',
],
framework: {
name: 'storybook-react-rsbuild',
options: {}
},
rsbuildFinal: (config) => {
return mergeRsbuildConfig(config, {
dev: {
client: {
overlay: false
}
},
tools: {
rspack: (config) => {
const mocksReplacementPlugins = [
new rspack.NormalModuleReplacementPlugin(/^\.\//, async (resource) => {
const mockedPath = path.resolve(
resource.context,
MOCKS_DIRECTORY,
resource.request
)
for (let ext of EXTENSIONS) {
const isReplacementPathExists = fs.existsSync(mockedPath + ext)
if (isReplacementPathExists) {
const newImportPath =
"./" + path.join(MOCKS_DIRECTORY, resource.request)
resource.request = newImportPath
break
}
}
}),
new rspack.NormalModuleReplacementPlugin(/^\.\.\//, async (resource) => {
const mockedPath = path.resolve(
resource.context,
MOCKS_DIRECTORY,
resource.request
)
for (let ext of EXTENSIONS) {
const isReplacementPathExists = fs.existsSync(mockedPath + ext)
if (isReplacementPathExists) {
const newImportPath =
"./" + path.join(MOCKS_DIRECTORY, resource.request)
resource.request = newImportPath
break
}
}
})
]
config.plugins = (config.plugins ?? []).concat(mocksReplacementPlugins)
return config
}
},
source: {
include: [
/node_modules[\\/]storybook-addon-remix-react-router[\\/]dist[\\/]index.js/
]
}
})
},
staticDirs: ['../public'],
docs: {
defaultName: "Docs",
docsMode: false,
autodocs: false,
},
}
but still no luck : same error.
Looks like the NormalReplacement plugin has no effect, though the code is the exact copy of the webpack addon.
I really don't understand where the problem is.
Thx by advance for any kind of help.