Skip to content

Commit

Permalink
Merge pull request #6206 from storybooks/fix/storysource-readme
Browse files Browse the repository at this point in the history
Update storysource readme with v5 webpack config
  • Loading branch information
shilman authored Mar 21, 2019
2 parents 5c26470 + 14b385b commit f580379
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions addons/storysource/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Storybook Storysource Addon

This addon is used to show stories source in the addon panel.
This addon is used to show stories source in the addon panel.

[Framework Support](https://github.com/storybooks/storybook/blob/master/ADDONS_SUPPORT.md)

Expand All @@ -23,7 +23,7 @@ import '@storybook/addon-storysource/register';
Use this hook to a custom webpack.config. This will generate a decorator call in every story:

```js
module.exports = function ({ config }) {
module.exports = function({ config }) {
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [require.resolve('@storybook/addon-storysource/loader')],
Expand All @@ -39,29 +39,31 @@ module.exports = function ({ config }) {
The loader can be customized with the following options:

### parser

The parser that will be parsing your code to AST (based on [prettier](https://github.com/prettier/prettier/tree/master/src/language-js))

Allowed values:
* `javascript` - default
* `typescript`
* `flow`

- `javascript` - default
- `typescript`
- `flow`

Usage:

```js
module.exports = function (baseConfig, env, defaultConfig) {
defaultConfig.module.rules.push({
module.exports = function({ config }) {
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [
{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: { parser: 'typescript' }
}
options: { parser: 'typescript' },
},
],
enforce: 'pre',
});

return defaultConfig;
return config;
};
```

Expand All @@ -70,6 +72,7 @@ module.exports = function (baseConfig, env, defaultConfig) {
The prettier configuration that will be used to format the story source in the addon panel.

Defaults:

```js
{
printWidth: 100,
Expand All @@ -80,11 +83,11 @@ Defaults:
}
```

Usage:
Usage:

```js
module.exports = function (baseConfig, env, defaultConfig) {
defaultConfig.module.rules.push({
module.exports = function({ config }) {
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [
{
Expand All @@ -93,14 +96,14 @@ module.exports = function (baseConfig, env, defaultConfig) {
prettierConfig: {
printWidth: 100,
singleQuote: false,
}
}
}
},
},
},
],
enforce: 'pre',
});

return defaultConfig;
return config;
};
```

Expand All @@ -109,54 +112,53 @@ module.exports = function (baseConfig, env, defaultConfig) {
The array of regex that is used to remove "ugly" comments.

Defaults:

```js
[/^eslint-.*/, /^global.*/]
[/^eslint-.*/, /^global.*/];
```

Usage:

```js
module.exports = function (baseConfig, env, defaultConfig) {
defaultConfig.module.rules.push({
module.exports = function({ config }) {
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [
{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: {
uglyCommentsRegex: [
/^eslint-.*/,
/^global.*/,
]
}
}
uglyCommentsRegex: [/^eslint-.*/, /^global.*/],
},
},
],
enforce: 'pre',
});

return defaultConfig;
return config;
};
```

### injectDecorator

Tell storysource whether you need inject decorator.If false, you need to add the decorator by yourself;

Defaults: true

Usage:

```js
module.exports = function (baseConfig, env, defaultConfig) {
defaultConfig.module.rules.push({
module.exports = function({ config }) {
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [
{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: { injectDecorator: false }
}
options: { injectDecorator: false },
},
],
enforce: 'pre',
});

return defaultConfig;
return config;
};
```

0 comments on commit f580379

Please sign in to comment.