我尝试用 Nuxt 项目中的组件制作故事书。到目前为止,我看到了组件,但它们都至少使用一个模块,我找不到导入它们的方法。我似乎并不孤单
(https://forum.vuejs.org/t/nuxt-js-and-storybook/26239,https://github.com/derekshull/nuxt-starter-kit-
v2/issues/1),
但我希望有人找到解决方案。
.storybook/webpack.config.js:
const path = require("@storybook\vue\dist\server\config\defaults\webpack.config.js");
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"],
include: path.resolve(__dirname, "../")
}
]
}
};
.storybook/config.js:
import { configure } from '@storybook/vue';
import Vue from 'vue';
const components = require.context('../components', true, /\.vue$/)
const stories = require.context('../components/stories', true, /.stories.js$/)
components.keys().forEach(filename => {
const [, componentName] = filename.match(/([\w-]+)(.vue)/)
Vue.component(componentName, components(filename).default)
})
function loadStories() {
stories.keys().forEach((filename) => req(filename))
};
configure(loadStories, module);