Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future - Create a CRA framework #18695

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 59 additions & 42 deletions addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,8 @@ export async function webpack(
? require.resolve('@storybook/mdx2-csf/loader')
: require.resolve('@storybook/mdx1-csf/loader');

// set `sourceLoaderOptions` to `null` to disable for manual configuration
const sourceLoader = sourceLoaderOptions
? [
{
test: /\.(stories|story)\.[tj]sx?$/,
loader: require.resolve('@storybook/source-loader'),
options: { ...sourceLoaderOptions, inspectLocalDependencies: true },
enforce: 'pre',
},
]
: [];

let rules = module.rules || [];

if (transcludeMarkdown) {
rules = [
...rules.filter((rule: any) => rule.test?.toString() !== '/\\.md$/'),
Expand All @@ -104,37 +93,65 @@ export async function webpack(
...module,
rules: [
...rules,
{
test: /(stories|story)\.mdx$/,
use: [
{
loader: resolvedBabelLoader,
options: createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }),
},
{
loader: mdxLoader,
options: {
...mdxLoaderOptions,
skipCsf: false,
Object.defineProperty(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the idea behind this construct?

Copy link
Member Author

@ndelangen ndelangen Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add a hidden property to the rule object, so it's easier to identify when you want to filter them out

{
test: /(stories|story)\.mdx$/,
use: [
{
loader: resolvedBabelLoader,
options: createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }),
},
},
],
},
{
test: /\.mdx$/,
exclude: /(stories|story)\.mdx$/,
use: [
{
loader: resolvedBabelLoader,
options: createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }),
},
{
loader: mdxLoader,
options: mdxLoaderOptions,
},
],
},
...sourceLoader,
{
loader: mdxLoader,
options: {
...mdxLoaderOptions,
skipCsf: false,
},
},
],
},
'custom_id',
{
value: 'storybook_mdx',
enumerable: false,
}
),
Object.defineProperty(
{
test: /\.mdx$/,
exclude: /(stories|story)\.mdx$/,
use: [
{
loader: resolvedBabelLoader,
options: createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }),
},
{
loader: mdxLoader,
options: mdxLoaderOptions,
},
],
},
'custom_id',
{
value: 'storybook_mdx',
enumerable: false,
}
),
// set `sourceLoaderOptions` to `null` to disable for manual configuration
...(sourceLoaderOptions
? [
Object.defineProperty(
{
test: /\.(stories|story)\.[tj]sx?$/,
loader: require.resolve('@storybook/source-loader'),
options: { ...sourceLoaderOptions, inspectLocalDependencies: true },
enforce: 'pre',
},
'custom_id',
{ enumerable: false, value: 'storybook_source' }
),
]
: []),
],
},
};
Expand Down
14 changes: 3 additions & 11 deletions examples/angular-cli/.storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
{
"extends": "../tsconfig.app.json",
"exclude": [
"../src/karma.ts",
"../src/**/*.spec.ts"
],
"include": [
"../src/**/*",
"preview.ts"
],
"exclude": ["../src/karma.ts", "../src/**/*.spec.ts"],
"include": ["../src/**/*", "preview.ts"],
"compilerOptions": {
"types": [
"@testing-library/jest-dom"
]
"types": ["@testing-library/jest-dom"]
}
}
5 changes: 2 additions & 3 deletions examples/cra-kitchen-sink/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { StorybookConfig } from '@storybook/react-webpack5';
import type { StorybookConfig } from '@storybook/cra';

const path = require('path');

const mainConfig: StorybookConfig = {
stories: ['../src/stories/**/*.stories.@(ts|tsx|js|jsx|mdx)'],
logLevel: 'debug',
addons: [
'@storybook/preset-create-react-app',
{
name: '@storybook/addon-docs/preset',
options: {
Expand Down Expand Up @@ -44,7 +43,7 @@ const mainConfig: StorybookConfig = {
breakingChangesV7: true,
},
framework: {
name: '@storybook/react-webpack5',
name: '@storybook/cra',
options: { fastRefresh: true },
},
};
Expand Down
8 changes: 2 additions & 6 deletions examples/cra-kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"react-scripts": "^5.0.1"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@storybook/addon-a11y": "7.0.0-alpha.16",
"@storybook/addon-actions": "7.0.0-alpha.16",
"@storybook/addon-backgrounds": "7.0.0-alpha.16",
Expand All @@ -30,13 +29,10 @@
"@storybook/addon-links": "7.0.0-alpha.16",
"@storybook/addon-storyshots": "7.0.0-alpha.16",
"@storybook/addons": "7.0.0-alpha.16",
"@storybook/builder-webpack5": "7.0.0-alpha.16",
"@storybook/preset-create-react-app": "^4.1.0",
"@storybook/cra": "7.0.0-alpha.16",
"@storybook/react": "7.0.0-alpha.16",
"@storybook/react-webpack5": "7.0.0-alpha.16",
"@storybook/theming": "7.0.0-alpha.16",
"storybook": "7.0.0-alpha.16",
"webpack": "5"
"storybook": "7.0.0-alpha.16"
},
"storybook": {
"chromatic": {
Expand Down
5 changes: 2 additions & 3 deletions examples/cra-ts-essentials/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { StorybookConfig } from '@storybook/react-webpack5';
import type { StorybookConfig } from '@storybook/cra';

const path = require('path');

const mainConfig: StorybookConfig = {
stories: ['../src/**/*.stories.@(ts|tsx|js|jsx|mdx)'],
addons: [
'@storybook/preset-create-react-app',
{
name: '@storybook/addon-essentials',
options: {
Expand Down Expand Up @@ -37,7 +36,7 @@ const mainConfig: StorybookConfig = {
buildStoriesJson: true,
breakingChangesV7: true,
},
framework: '@storybook/react-webpack5',
framework: '@storybook/cra',
};

module.exports = mainConfig;
7 changes: 2 additions & 5 deletions examples/cra-ts-essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@
"devDependencies": {
"@storybook/addon-essentials": "7.0.0-alpha.16",
"@storybook/addons": "7.0.0-alpha.16",
"@storybook/builder-webpack5": "7.0.0-alpha.16",
"@storybook/preset-create-react-app": "^4.1.0",
"@storybook/cra": "7.0.0-alpha.16",
"@storybook/react": "7.0.0-alpha.16",
"@storybook/react-webpack5": "7.0.0-alpha.16",
"@storybook/testing-library": "^0.0.9",
"storybook": "7.0.0-alpha.16",
"ts-node": "^10.4.0",
"webpack": "5"
"ts-node": "^10.4.0"
},
"storybook": {
"chromatic": {
Expand Down
5 changes: 2 additions & 3 deletions examples/cra-ts-kitchen-sink/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { StorybookConfig } from '@storybook/react-webpack5';
import type { StorybookConfig } from '@storybook/cra';

const path = require('path');

const mainConfig: StorybookConfig = {
stories: ['../src/components', '../src/stories'],
logLevel: 'debug',
addons: [
'@storybook/preset-create-react-app',
'@storybook/addon-docs',
'@storybook/addon-actions',
'@storybook/addon-links',
Expand Down Expand Up @@ -38,7 +37,7 @@ const mainConfig: StorybookConfig = {
buildStoriesJson: true,
breakingChangesV7: true,
},
framework: '@storybook/react-webpack5',
framework: '@storybook/cra',
};

module.exports = mainConfig;
7 changes: 2 additions & 5 deletions examples/cra-ts-kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,16 @@
"@storybook/addon-highlight": "7.0.0-alpha.16",
"@storybook/addon-links": "7.0.0-alpha.16",
"@storybook/addons": "7.0.0-alpha.16",
"@storybook/builder-webpack5": "7.0.0-alpha.16",
"@storybook/preset-create-react-app": "^4.1.0",
"@storybook/cra": "7.0.0-alpha.16",
"@storybook/react": "7.0.0-alpha.16",
"@storybook/react-webpack5": "7.0.0-alpha.16",
"@types/enzyme": "^3.10.8",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.9.1",
"enzyme-to-json": "^3.6.1",
"fork-ts-checker-webpack-plugin": "^7.2.6",
"react-moment-proptypes": "^1.7.0",
"storybook": "7.0.0-alpha.16",
"ts-node": "^10.4.0",
"webpack": "5"
"ts-node": "^10.4.0"
},
"storybook": {
"chromatic": {
Expand Down
3 changes: 1 addition & 2 deletions examples/html-kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@storybook/addon-highlight": "7.0.0-alpha.16",
"@storybook/addon-jest": "7.0.0-alpha.16",
"@storybook/addon-links": "7.0.0-alpha.16",
"@storybook/addon-postcss": "^2.0.0",
"@storybook/addon-postcss": "^3.0.0-alpha.1",
"@storybook/addon-storyshots": "7.0.0-alpha.16",
"@storybook/addon-storysource": "7.0.0-alpha.16",
"@storybook/addon-viewport": "7.0.0-alpha.16",
Expand All @@ -36,7 +36,6 @@
"format-json": "^1.0.3",
"global": "^4.4.0",
"postcss": "^8.2.4",
"postcss-color-rebeccapurple": "^6.0.0",
"storybook": "7.0.0-alpha.16"
},
"storybook": {
Expand Down
2 changes: 0 additions & 2 deletions examples/html-kitchen-sink/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ module.exports = {
plugins: [
// eslint-disable-next-line global-require
require('autoprefixer'),
// eslint-disable-next-line global-require
require('postcss-color-rebeccapurple'),
],
};
7 changes: 4 additions & 3 deletions frameworks/angular/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/core-common';
import { StorybookConfig } from './types';

Expand All @@ -7,6 +7,7 @@ export const addons: PresetProperty<'addons', StorybookConfig> = [
require.resolve('./server/framework-preset-angular-cli'),
require.resolve('./server/framework-preset-angular-ivy'),
require.resolve('./server/framework-preset-angular-docs'),
dirname(require.resolve(join('@storybook/builder-webpack5', 'package.json'))),
];

export const previewAnnotations: StorybookConfig['previewAnnotations'] = (entries = []) => [
Expand All @@ -20,8 +21,8 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
name: dirname(
require.resolve(join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
Expand Down
8 changes: 4 additions & 4 deletions frameworks/angular/src/server/framework-preset-angular-cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import webpack from 'webpack';
import type { Configuration } from 'webpack';
import { logger } from '@storybook/node-logger';
import { targetFromTargetString, BuilderContext, Target } from '@angular-devkit/architect';
import { sync as findUpSync } from 'find-up';
Expand All @@ -18,7 +18,7 @@ import {
readAngularWorkspaceConfig,
} from './angular-read-workspace';

export async function webpackFinal(baseConfig: webpack.Configuration, options: PresetOptions) {
export async function webpack(baseConfig: Configuration, options: PresetOptions) {
if (!moduleIsAvailable('@angular-devkit/build-angular')) {
logger.info('=> Using base config because "@angular-devkit/build-angular" is not installed');
return baseConfig;
Expand All @@ -33,9 +33,9 @@ export async function webpackFinal(baseConfig: webpack.Configuration, options: P
info: string;
condition: boolean;
getWebpackConfig(
baseConfig: webpack.Configuration,
baseConfig: Configuration,
options: PresetOptions
): Promise<webpack.Configuration> | webpack.Configuration;
): Promise<Configuration> | Configuration;
}[] = [
{
info: '=> Loading angular-cli config for angular >= 13.0.0',
Expand Down
37 changes: 37 additions & 0 deletions frameworks/cra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Storybook for CRA

Storybook for CRA is a UI development environment for your React components.
With it, you can visualize different states of your UI components and develop them interactively.

![Storybook Screenshot](https://github.com/storybookjs/storybook/blob/main/media/storybook-intro.gif)

Storybook runs outside of your app.
So you can develop UI components in isolation without worrying about app specific dependencies and requirements.

## Getting Started

```sh
cd my-react-app
npx sb init
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
npx sb init
npx storybook init

```

For more information visit: [storybook.js.org](https://storybook.js.org)

---

Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish.
You can also build a [static version](https://storybook.js.org/docs/react/sharing/publish-storybook) of your Storybook and deploy it anywhere you want.

Here are some featured storybooks that you can reference to see how Storybook works:

- [Demo of Storybook Design System](https://storybook.js.org/design-system) - [source](https://github.com/storybookjs/design-system)

## Create React App

TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO!


## Docs

- [Basics](https://storybook.js.org/docs/react/get-started/introduction)
- [Configurations](https://storybook.js.org/docs/react/configure/overview)
- [Addons](https://storybook.js.org/docs/react/configure/storybook-addons)
Loading