vue2 安装 storybook(6.x) 记录
作者:互联网
- vue-cli 执行create操作 创建vue2项目
vue create my-storybook
- storybook的init操作
npx sb init
- 引入sass
storybook文档指向的github仓库有安装sass的方法
yarn add -D @storybook/preset-scss css-loader sass sass-loader style-loader
Then add the following to .storybook/main.js
:
module.exports = {
addons: ['@storybook/preset-scss'],
};
4.启动storybook 报错vue-loader 自行安装vue-loader
yarn add vue-loader
猜测:
启动storybook是默认webpack启动的,webpack运行vue是需要vue-loader来处理的,而默认的vue-cli似乎是不需要(猜的
5.继续报错。猜测scss在vue单组件里面无法解析,相关解决办法应该是storybook的webpack配置里面加入scss相关的loader配置
// .storybook/mian.js
const path = require('path');
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials"
],
webpackFinal: async (config, { configType }) => {
// `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION'
// You can change the configuration based on that.
// 'PRODUCTION' is used when building the static version of storybook.
// Make whatever fine-grained changes you need
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
});
// Return the altered config
return config;
},
}
最后根据项目需求再次安装node-sass 版本不能过高
标签:scss,vue,sass,config,loader,storybook,vue2,安装 来源: https://www.cnblogs.com/Eyeseas/p/vue2-an-zhuang-storybook6x-ji-lu.html