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

Add support for Storybook custom builder #10585

Closed
Jordan-Hall opened this issue Jun 4, 2022 · 10 comments · Fixed by #10662
Closed

Add support for Storybook custom builder #10585

Jordan-Hall opened this issue Jun 4, 2022 · 10 comments · Fixed by #10662
Assignees
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug

Comments

@Jordan-Hall
Copy link
Contributor

Currently storybook requires either webpack or webpack5 set in the { core: { builder: '...' } }

I've been wanting to use more custom builder for plugins without having to fork the whole storybook integration. For example:

const rootMain = require('../../../.storybook/main');

module.exports = {
  ...rootMain,

  core: { ...rootMain.core, builder: '@storybook/builder-vite' },

  stories: [
    ...rootMain.stories,
    '../src/lib/**/*.stories.mdx',
    '../src/lib/**/*.stories.@(js|jsx|ts|tsx)',
  ],
  addons: [...rootMain.addons, '@nrwl/react/plugins/storybook'],

  async webpackFinal(config, { configType }) {
    // apply any global webpack configs that might have been specified in .storybook/main.js
    if (rootMain.webpackFinal) {
      config = await rootMain.webpackFinal(config, { configType });
    }

    // add your own webpack tweaks if needed

    return config;
  }
};


@AgentEnder AgentEnder added the scope: storybook Issues related to Storybook support in Nx label Jun 6, 2022
@mandarini
Copy link
Member

Hi there @Jordan-Hall ! What happens when you make that change to your main.js?

@Jordan-Hall
Copy link
Contributor Author

@mandarini it says its reverts to webpack 4

@mandarini
Copy link
Member

Ohhhhhhhhhhhhhhh I know the issue! Ok, will look into this soon. I'm on PTO after PTO these days, but next week it will be my priority! :)

@mandarini
Copy link
Member

I know the message says so, but does it actually use webpack4, or maybe it does use your builder-vite but just says it uses webpack 4?

@Jordan-Hall
Copy link
Contributor Author

I know the message says so, but does it actually use webpack4, or maybe it does use your builder-vite but just says it uses webpack 4?

Yes it uses the vite under it. Sorry, the warning message thrown me off because of other issues I was facing! I didn't have time to debug it fully until now.

@mandarini
Copy link
Member

Perfect!!!! Thanks these answers were super helpful!!! :D :D Just bad messaging, easy to fix!! Thanks @Jordan-Hall !

@mandarini mandarini self-assigned this Jun 8, 2022
@mandarini
Copy link
Member

Note to self: fix messaging and core builder check for Storybook

@Jordan-Hall
Copy link
Contributor Author

I'll let you know if this is exactly the issue. WIth the setup I have it appears to still be running on webpack (At least thats what it says). I notice now #10584 is saying bable-loader being used so will need to debug for longer. However at the same time all the viteFinal config is being called as expected.

@mandarini
Copy link
Member

mandarini commented Jun 9, 2022

Hi @Jordan-Hall ! I'm testing this out, right now!

Sooooo, great news!!!

I just tested this! I installed vite and @storybook/builder-vite. Then, in my React projects's .storybook/main.js I changed the builder to this: builder: '@storybook/builder-vite'.

Then I just did nx storybook my-project and it works like a charm.

Screenshot 2022-06-09 at 12 40 40 PM

Here is my repo. I had to do nothing more, it just works! I just need to remove that webpack4 message, which is disorienting! Here are the changes from the default Storybook setup as Nx creates it, to move to vite.

Please please let me know if it works for you!

You can also read the docs on the vite builder!

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants