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

Fix issue with require by replacing with dynamic imports for ES module compatibility #499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ declare var DataTable: any;
declare var Dropzone: any;
declare var noUiSlider: any;

let HSDataTableModule;
let HSFileUploadModule;
let HSRangeSliderModule;
let HSDataTableModule = null;
let HSFileUploadModule = null;
let HSRangeSliderModule = null;

export { default as HSCopyMarkup } from './plugins/copy-markup';
export { default as HSAccordion } from './plugins/accordion';
Expand All @@ -37,17 +37,20 @@ export { default as HSTooltip } from './plugins/tooltip';
export { default as HSTreeView } from './plugins/tree-view';
export { default as HSStaticMethods } from './static';

if (typeof DataTable !== 'undefined' && typeof jQuery !== 'undefined')
HSDataTableModule = require('./plugins/datatable').default;
else HSDataTableModule = null;
export { HSDataTableModule as HSDataTable };
(async () => {
if (typeof DataTable !== 'undefined' && typeof jQuery !== 'undefined') {
HSDataTableModule = (await import('./plugins/datatable')).default;
}

if (typeof _ !== 'undefined' && typeof Dropzone !== 'undefined')
HSFileUploadModule = require('./plugins/file-upload').default;
else HSFileUploadModule = null;
export { HSFileUploadModule as HSFileUpload };
if (typeof _ !== 'undefined' && typeof Dropzone !== 'undefined') {
HSFileUploadModule = (await import('./plugins/file-upload')).default;
}

if (typeof noUiSlider !== 'undefined') {
HSRangeSliderModule = (await import('./plugins/range-slider')).default;
}
})();

if (typeof noUiSlider !== 'undefined')
HSRangeSliderModule = require('./plugins/range-slider').default;
else HSRangeSliderModule = null;
export { HSDataTableModule as HSDataTable };
export { HSFileUploadModule as HSFileUpload };
export { HSRangeSliderModule as HSRangeSlider };