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

fix(www): update storybook docs to prefer Gatsby ES6 module in webpack config #10669

Merged
merged 1 commit into from
Dec 27, 2018

Conversation

sidharthachatterjee
Copy link
Contributor

The steps in the current documentation for using Storybook with Gatsby (https://www.gatsbyjs.org/docs/visual-testing-with-storybook/) don't work because importing Link from gatsby in any component breaks.

This is because several internals get required as a result of requiring anything from the default commonjs build (which would have been tree shaken before #9123) and eventually require a non-existent pages.json.

More details are at #10668

This pull request updates the documentation with a quick fix (setting resolve.mainFields in the storybook webpack config override thereby preferring es6 gatsby over commonjs)

Fixes #10662

@sidharthachatterjee sidharthachatterjee added the type: documentation An issue or pull request for improving or updating Gatsby's documentation label Dec 26, 2018
@sidharthachatterjee sidharthachatterjee requested review from kkemple and a team December 26, 2018 18:51
@@ -85,6 +85,9 @@ module.exports = (baseConfig, env, defaultConfig) => {
require.resolve("@babel/plugin-proposal-class-properties"),
]

// Prefer Gatsby ES6 entrypoint (module) over commonjs (main) entrypoint
defaultConfig.resolve.mainFields = ["browser", "module", "main"]
Copy link
Contributor

@DSchau DSchau Dec 27, 2018

Choose a reason for hiding this comment

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

I'm pretty surprised this isn't the way this already works.

I believe Webpack works this way--and Storybook uses Webpack afaik, so this is odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DSchau The defaultConfig from storybook has mainFields: ['browser', 'main', 'module'],

I think it gets set at https://github.com/storybooks/storybook/blob/0ef3f40d678fb42ca74505e99cc3ad2449c3bfdf/lib/core/src/server/preview/iframe-webpack.config.js#L84

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder how this will affect other modules outside of gatsby, with that said I think we should make the change to docs still

@@ -85,6 +85,9 @@ module.exports = (baseConfig, env, defaultConfig) => {
require.resolve("@babel/plugin-proposal-class-properties"),
]

// Prefer Gatsby ES6 entrypoint (module) over commonjs (main) entrypoint
defaultConfig.resolve.mainFields = ["browser", "module", "main"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder how this will affect other modules outside of gatsby, with that said I think we should make the change to docs still

@sidharthachatterjee
Copy link
Contributor Author

Thanks @kkemple

We can probably remove this too once we fix the underlying issue at #10668

@DSchau DSchau merged commit 4a6ef93 into master Dec 27, 2018
@DSchau DSchau deleted the docs/update-webpack-config-for-storybook branch December 27, 2018 17:15
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
…k config (gatsbyjs#10669)

The steps in the current documentation for using Storybook with Gatsby (https://www.gatsbyjs.org/docs/visual-testing-with-storybook/) don't work because importing Link from gatsby in any component breaks. 

This is because several internals get required as a result of requiring anything from the default commonjs build (which would have been tree shaken before gatsbyjs#9123) and eventually require a non-existent `pages.json`. 

More details are at gatsbyjs#10668

This pull request updates the documentation with a quick fix (setting resolve.mainFields in the storybook webpack config override thereby _preferring_ es6 gatsby over commonjs) 

Fixes gatsbyjs#10662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gatsby Version >= 2.0.24 breaks Storybook support
3 participants