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 option to exclude shared dependencies from build #2795

Open
2 tasks done
tky753 opened this issue Jul 25, 2024 · 6 comments
Open
2 tasks done

add option to exclude shared dependencies from build #2795

tky753 opened this issue Jul 25, 2024 · 6 comments

Comments

@tky753
Copy link

tky753 commented Jul 25, 2024

Clear and concise description of the problem

I use rsbuild for building, and want to minimize my remote module size,
so I don't want shared dependencies generated on remotes as I can load it from my host.
I tried these config in rsbuild.config.ts:

import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack'
......
  output: {
    externals: ["react"]
  },
  tools: {
    rspack: (config, { appendPlugins }) => {
      appendPlugins([
        new ModuleFederationPlugin({
          shared: {
            react: { singleton: true }
          }
       })
    }
  }

but where I run rsbuild build, shared react is still generated at:
dist\static\js\async\lib-react.e00de504.js

Suggested solution

add ModuleFederationPluginOptions options:

/* exclude shared dependencies from build, default: false */
external?:  boolean

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@2heal1
Copy link
Member

2heal1 commented Jul 26, 2024

you can set shared: { react: { import:false } }

@2heal1
Copy link
Member

2heal1 commented Jul 26, 2024

{ import: false } means shared will not be bundled into dist

@tky753
Copy link
Author

tky753 commented Jul 29, 2024

you can set shared: { react: { import:false } }

@2heal1 I tried it, not work, still lib-react.xxxxxxxx.js generated

@itmanyong
Copy link

+1

@ScriptedAlchemy
Copy link
Member

react-lib is a chunk group. It includes react, react-dom, react/jsx-runtime, schedular. Youd need to look through the chunks contents and make them all external. react-lib is just a name, might not even have react in it if you look closer

@ScriptedAlchemy
Copy link
Member

pluginReact({splitChunks: {react: false, router: false}}) or something like that. Will disable the react chunk group entirely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants