-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix/12745 babel config loading #15628
Changes from all commits
61d535f
5c24415
977f0fe
0f3a37d
094fc12
07576b4
a5a58a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import JSON5 from 'json5'; | |
|
||
import { logger } from '@storybook/node-logger'; | ||
import { TransformOptions } from '@babel/core'; | ||
import { serverRequire } from '..'; | ||
|
||
function removeReactHmre(presets: TransformOptions['presets']) { | ||
const index = presets.indexOf('react-hmre'); | ||
|
@@ -25,7 +26,7 @@ function loadFromPath(babelConfigPath: string): TransformOptions { | |
|
||
try { | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
config = require(babelConfigPath); | ||
config = serverRequire(babelConfigPath); | ||
logger.info('=> Loading custom babel config as JS'); | ||
} catch (e) { | ||
error.js = e; | ||
|
@@ -48,10 +49,16 @@ function loadFromPath(babelConfigPath: string): TransformOptions { | |
throw error.js; | ||
} | ||
|
||
config = { ...config, babelrc: false }; | ||
if (config instanceof Function) { | ||
config = config(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling the config function without an argument could be problematic. Babel calls the function with an |
||
} | ||
|
||
config = { ...config, babelrc: false, configFile: false }; | ||
} | ||
|
||
if (!config) return null; | ||
if (!config) { | ||
return null; | ||
} | ||
|
||
// Remove react-hmre preset. | ||
// It causes issues with react-storybook. | ||
|
@@ -69,10 +76,7 @@ function loadFromPath(babelConfigPath: string): TransformOptions { | |
return config; | ||
} | ||
|
||
export const loadCustomBabelConfig = async function ( | ||
configDir: string, | ||
getDefaultConfig: () => TransformOptions | ||
) { | ||
export const loadCustomBabelConfig = async (configDir: string) => { | ||
// Between versions 5.1.0 - 5.1.9 this loaded babel.config.js from the project | ||
// root, which was an unintentional breaking change. We can add back project support | ||
// in 6.0. | ||
|
@@ -81,6 +85,7 @@ export const loadCustomBabelConfig = async function ( | |
loadFromPath(path.resolve(configDir, '.babelrc.json')) || | ||
loadFromPath(path.resolve(configDir, '.babelrc.js')) || | ||
loadFromPath(path.resolve(configDir, 'babel.config.json')) || | ||
loadFromPath(path.resolve(configDir, 'babel.config.ts')) || | ||
loadFromPath(path.resolve(configDir, 'babel.config.js')); | ||
|
||
if (babelConfig) { | ||
|
@@ -92,5 +97,5 @@ export const loadCustomBabelConfig = async function ( | |
return babelConfig; | ||
} | ||
|
||
return getDefaultConfig(); | ||
return null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the code https://github.com/storybookjs/storybook/blob/next/lib/core-common/src/utils/load-custom-babel-config.ts#L79 there are more filenames considered for loading in the
.storybook
folderThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important to note as well that the recommended setting for Babel 7 is to use
babel.config.json
, lots of people are renaming their configuration file so it would be nice indeed to see that extension in the docsRef: https://babeljs.io/docs/en/config-files#6x-vs-7x-babelrc-loading