mymth / vanillajs-datepicker

A vanilla JavaScript remake of bootstrap-datepicker for Bulma and other CSS frameworks
MIT License
719 stars 147 forks source link

How can be imported as module in an html page? #180

Open yourchoice opened 3 months ago

yourchoice commented 3 months ago

How can be imported as module in html pages ?

I tried:

In main html I load script main.js with click listener to an input :

document.querySelector('.dpr-input')?.addEventListener("click", event => {
       const el = event.target;
    (async () => {
        const { Datepicker } =  await import('/assets/plugins/vanillajs-datepicker/index.es.js');

        new DateRangePicker( .... );
    })();
});

And index.es.js file

import Datepicker from './js/Datepicker.js';
export Datepicker;// I tried and export default Datepicker;

But i get errors like: The requested module './Datepicker.js' does not provide an export named 'default' (at index.es.js) or Uncaught (in promise) SyntaxError: Unexpected token 'export' (at index.es.js)

Please if somebody can help me how to import - export without errors.

Thank You!