因此,在开发人员辞职后,我继承了一个小型故事书库,而我的 webpack/故事书不是我的强项。
问题是配置 Storybook 构建以输出可导出组件有多容易。我想把我的 Storybook 组件(不是组件的故事,而是底层组件本身)变成一个私有的 npm 包,这样我就可以将它们导出到其他项目中。
我的故事书是@storybook react 3.2.11 running typescript / scss 我的文件结构看起来像这样......
src
components
Button
Button.tsx
button.scss
Dropdown
..etc
stories
components
Buttonstory
ButtonStory.tsx
index.tsx
我的 config.js 看起来像这样......
import { configure } from '@storybook/react';
function loadStories() {
require('../src/stories/index.tsx');
// You can require as many stories as you need.
}
configure(loadStories, module);
我的 .storybook webpack.config.js 看起来像这样。
const path = require("path");
const autoprefixer = require("autoprefixer");
const genDefaultConfig =
require('@storybook/react/dist/server/config/defaults/webpack.config.js');
const stylelint = require('stylelint');
const stylelintPlugin = require("stylelint-webpack-plugin");
module.exports = (baseConfig, env) => {
const config = genDefaultConfig(baseConfig, env);
// Reset rules
config.module.rules = [];
/**
* Typescript handling
* Allows webpack to process ts and tsx files using the typescript compiler.
*/
config.module.rules.push({
test: /\.(tsx?)$/,
enforce: "pre",
loader: require.resolve("tslint-loader")
});
config.module.rules.push({
test: /\.(tsx?)$/,
loader: require.resolve('awesome-typescript-loader')
});
config.resolve.extensions.push('.ts', '.tsx');
/**
* Style handling
*
* There are four loaders for handling the styling import process their hierachy is as follows:
*
* sass-loader -> postcss -> css-loader -> style-loader
*/
config.module.rules.push({
test: /\.(scss)$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 2
}
},
{
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss',
sourceMap: true,
plugins: function plugins() {
return [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9'],
flexbox: 'no-2009'
})
]
}
}
},
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: true
}
},
]
})
/**
* Begin storybook defaults
* These are the storybook defaults that we have not written over. Pretty much everything except
* styling loader and imports.
*/
config.module.rules = config.module.rules.concat([
{
test: /\.json$/,
loader: require.resolve('json-loader')
},
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
loader: require.resolve('file-loader'),
query: {
name: 'static/media/[name].[hash:8].[ext]'
}
},
{
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
loader: require.resolve('url-loader'),
query: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
}
]);
/**
* Add stylelint as a plugin, doing this because you need this to run before postCSS and as of the
* of this writing I couldn't be bothered reconfiguring postCSS to process the SCSS.
*/
config.plugins.push(new stylelintPlugin({
files: "**/*.scss",
emitErrors: false,
failOnError: false
}));
return config;
};
想知道是否有人设置了类似的东西