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

unable to have a singleton service without barrel imports #4322

Open
nischaym-next opened this issue Dec 10, 2024 · 0 comments
Open

unable to have a singleton service without barrel imports #4322

nischaym-next opened this issue Dec 10, 2024 · 0 comments

Comments

@nischaym-next
Copy link

nischaym-next commented Dec 10, 2024

I am looking to import from one the shared libs without the barrel import file (index.ts) so that my bundle files gets smaller.
example:
Before
import { blahService } from '@shared-services'
After
import { blahService } from '@shared-services/blahservice'

my bundle is right now bloated given importing any of the services is importing all the services, without the barrel imports my bundle size reduce from 250kb to 50kb
BUT
the services are getting initated multiple times (twice) i.e blahService logs twice when i put a console.log in its constructor

my tsconfig.base.json
"@shared-services/*": ["libs/shared-services/src/lib/*"],
previously this was "@shared-services": ["libs/shared-services/src/index"],
my module-federation.base.config.ts

  additionalShared: [
    {
      libraryName: '@shared-services',
      sharedConfig: {
        requiredVersion: '*',
        singleton: true,
        import: 'libs/shared-services/src/lib/*', --> previously this was libs/shared-services/src/index
      },
    },
  ],

so how to have a singleton without the barrel imports ?

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

1 participant