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

Presets - API generalization #4173

Merged
merged 4 commits into from
Sep 16, 2018
Merged

Conversation

igor-dv
Copy link
Member

@igor-dv igor-dv commented Sep 13, 2018

Issue:
The presets API, in the beginning, was to expose these methods: babel, webpack, preview & manager. Each one is about to extend a relevant part in the SB configuration.

After that, babelDefault was added to solve the babel 6 compatibility problems and remove the complexity of babel-merge.

What I did

From now, the core will expose presets loader that only knows to do the apply. Then core will wrap the apply with babel, webpack, preview & manager. Since presets object is passed deeper to the presets chain, any other preset will be able to extend it with the new functionality.

@pksunkara
Copy link
Member

@igor-dv I still don't get the difference between babelDefault and babel. Is it like babelDefault is for babel@6?

@igor-dv
Copy link
Member Author

igor-dv commented Sep 13, 2018

One of the steps in babel config combination is loadCustomBabelConfig.js

export default function(configDir, getDefaultConfig) {
  const babelConfig = loadFromPath(path.resolve(configDir, '.babelrc'));

  if (babelConfig) {
    // If the custom config uses babel's `extends` clause, then replace it with
    // an absolute path. `extends` will not work unless we do this.
    if (babelConfig.extends) {
      babelConfig.extends = path.resolve(configDir, babelConfig.extends);
    }
    return babelConfig;
  }

  return isBabelLoader8() ? getDefaultConfig() : {};
}

it tries to load a custom babelrc from the .storybook dir, if it's not existing, and user is using babe 7, we are providing our default babel configuration.

Default babel config is also located in core (babe.dev.js and babel.prod.js)

There are some apps, (react, mithril and vue) that have to extend the defulat config with their plugins/presets, and we want to extend only our default config, and not the one, user provided in a .storybook dir.

In the beginning, I wanted to merge the defaults anyway with what user provides, and @Hypnosphi mentioned that it could break if user uses babel 6.

@igor-dv igor-dv merged commit 91b322d into master Sep 16, 2018
@igor-dv igor-dv deleted the presets/even-more-generalization branch September 16, 2018 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants