Currently, the library contains multiple frameworks in one npm module (which is admittedly not the best practice). However, as we work on splitting the library into separate JS framework specific repositories like React, JQuery, Angular, etc., I'm faced with a challenge.
I need to figure out how to export only one of the libraries without including the others. For instance, if I'm using React, I don't want the jQuery module to be exported when there's only one "main" entry in the package.json
.
One approach could be importing the module through a relative directory path like
from './node_modules/ui-combined-module/src/react/dist.js';
, but that solution seems messy and impractical.
To address this issue, here are some options for your example code:
// Use one of the following in your example code:
// import {react as UILibraryReact} from 'ui-combined-module';
// const Badge = UILibraryReact.Badge;
// import {jquery as UILibraryJquery} from 'ui-combined-module';
// const Badge = UILibraryJquery.Badge;
import * as react from './react/dist';
import * as jquery from './jquery/dist';
module.exports = {
react,
jquery
};