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

[Bug]: I use MUI and Storybook to create the new UI library, here I used light and dark theme to customize 'Button' component color, its theme is working properly in local dev environment. but not working on using the component from 'dist' directory after npm run build. #17899

Closed
7 tasks done
rick-liyue-huang opened this issue Aug 19, 2024 · 2 comments

Comments

@rick-liyue-huang
Copy link

Describe the bug

I use MUI and Storybook to create the new UI library, here I used light and dark theme to customize 'Button' component color, its theme is working properly in local dev environment. but not working on using the component from 'dist' directory after npm run build. please see the detail of 'App.tsx' file, in which its working good on import { Button } from './components' and will lose theme when import { Button } from '../dist/try-ui-core-component'.

Reproduction

https://stackblitz.com/~/github.com/rick-liyue-huang/try-ui-core-component

Steps to reproduce

No response

System Info

window, 'npm create vite@latest my-vue-app -- --template reat-ts', 'npx storybook@latest init', 'npm install @mui/material @emotion/react @emotion/styled'

Used Package Manager

npm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Aug 20, 2024

That sounds like React context got duplicated due to lib bundling. To avoid this, usually you need to copy all dependencies from package.json to rollupOptions.external something like:

https://stackblitz.com/edit/github-ghg571?file=vite.config.ts

import pkg from "./package.json"

export default defineConfig({
    ...
    build: {
        lib: {
            formats: ["es"],
            entry: path.resolve(__dirname, './src/components/index.tsx'),
            fileName: 'try-ui-core-component',
        },
        rollupOptions: {
            external: Object.keys(pkg.dependencies),
        },
    },
})

@hi-ogawa
Copy link
Collaborator

Closing as the config I provided is working.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants