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

StorybookConfig: Add babel field #15220

Closed
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion addons/essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@
"@types/webpack-env": "^1.16.0"
},
"peerDependencies": {
"@babel/core": "^7.9.6"
"@babel/core": "^7.12.10",
"@storybook/vue": "6.5.0-alpha.23",
"@storybook/web-components": "6.5.0-alpha.23",
"babel-loader": "^8.0.0",
"lit-html": "^1.4.1 || ^2.0.0-rc.3",
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0",
"webpack": "*"
},
"peerDependenciesMeta": {
"@storybook/angular": {
Expand Down
2 changes: 1 addition & 1 deletion app/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"webpack": "4"
},
"peerDependencies": {
"@babel/core": "^7.11.5",
"@babel/core": "^7.12.10",
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0"
},
Expand Down
4 changes: 4 additions & 0 deletions lib/core-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ export interface StorybookConfig {
*/
refs?: StorybookRefs | ((config: Configuration, options: Options) => StorybookRefs);

/**
* Modify or return a custom Babel config.
*/
babel?: (config: TransformOptions) => TransformOptions | Promise<TransformOptions>;
/**
* Modify or return a custom Webpack config.
*/
Expand Down
1 change: 1 addition & 0 deletions lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@babel/core": "^7.12.10",
"@discoveryjs/json-ext": "^0.5.3",
"@storybook/builder-webpack4": "6.5.0-alpha.42",
"@storybook/core-client": "6.5.0-alpha.42",
Expand Down
14 changes: 10 additions & 4 deletions lib/core-server/src/presets/babel-cache-preset.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { resolvePathInStorybookCache } from '@storybook/core-common';
import { TransformOptions } from '@babel/core';

// FIXME: babelConfig is maybe a TransformOptions?
const extend = (babelConfig: any) => ({
type Extend = (
babelConfig: TransformOptions
) => TransformOptions & {
cacheDirectory: string;
};

const extend: Extend = (babelConfig) => ({
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables a cache directory for faster-rebuilds
cacheDirectory: resolvePathInStorybookCache('babel'),
...babelConfig,
});

export const babel = extend;
export const managerBabel = extend;
export const babel: Extend = extend;
export const managerBabel: Extend = extend;
12 changes: 10 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6562,7 +6562,14 @@ __metadata:
regenerator-runtime: ^0.13.7
ts-dedent: ^2.0.0
peerDependencies:
"@babel/core": ^7.9.6
"@babel/core": ^7.12.10
"@storybook/vue": 6.5.0-alpha.23
"@storybook/web-components": 6.5.0-alpha.23
babel-loader: ^8.0.0
lit-html: ^1.4.1 || ^2.0.0-rc.3
react: ^16.8.0 || ^17.0.0
react-dom: ^16.8.0 || ^17.0.0
webpack: "*"
peerDependenciesMeta:
"@storybook/angular":
optional: true
Expand Down Expand Up @@ -7639,6 +7646,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/core-server@workspace:lib/core-server"
dependencies:
"@babel/core": ^7.12.10
"@discoveryjs/json-ext": ^0.5.3
"@storybook/builder-webpack4": 6.5.0-alpha.42
"@storybook/builder-webpack5": 6.5.0-alpha.42
Expand Down Expand Up @@ -8297,7 +8305,7 @@ __metadata:
ts-dedent: ^2.0.0
webpack: 4
peerDependencies:
"@babel/core": ^7.11.5
"@babel/core": ^7.12.10
react: ^16.8.0 || ^17.0.0
react-dom: ^16.8.0 || ^17.0.0
peerDependenciesMeta:
Expand Down