unable to have a singleton service without barrel imports
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 ?
use a trailing slash.
"lodash/" instead of "lodash" for example.
??
Oh this looks like nx. I'm not sure how this works in nx. Will need to check