0

ember-moment-shim is an ember addon that generates the locales conditionally based on Moment.js and Moment-Timezone.

Any tools or processes to accomplish the same with just DayJs instead.

Ref: https://github.com/jasonmit/ember-cli-moment-shim

UPDATE:

I want to lazy load or dynamically load the dayJs locales based on the requirement. And every time you need to load a locale, you need to import it like

import fr from 'dayjs/locale/fr'

just that it would be a different locale every time and could change on refresh based on the settings from API response.

ember-auto-import throws following Error

Uncaught SyntaxError: Cannot use import statement outside a module*
Sarath Damaraju
  • 309
  • 2
  • 13
  • Have you tried just to use `ember-auto-import`? – Lux Dec 23 '19 at 06:47
  • Yes, it throws Uncaught Error. Updated the question accordingly – Sarath Damaraju Dec 23 '19 at 08:54
  • Please add the code that surrounds `import fr from 'dayjs/locale/fr'`. Where are you running that? How do you get `based on the settings from API response. `. Also have you followed the instructions to use Dynamic imports: https://github.com/ef4/ember-auto-import#dynamic-import – jrjohnson Dec 23 '19 at 16:52

1 Answers1

1

Addons like ember-cli-moment-shim are no longer required to use libraries from NPM instead you can use them directly after installing ember-auto-import.

From the command line do:

ember install ember-auto-import
npm install dayjs

Then you can just import dayjs where you need it.

For example in a component:

//app/components/today.js
import dayjs from 'dayjs';
import Component from '@glimmer/component';

export default class TodayComponent extends Component {
  today = dayjs().format();
}
jrjohnson
  • 2,401
  • 17
  • 23
  • It is already been used. And seems to be not working for my case. I have updated the question accordingly. – Sarath Damaraju Dec 23 '19 at 09:00
  • What is the browser support for dynamic-imports? To be even specific, does it support Browsers >= IE11 ? – Sarath Damaraju Jan 09 '20 at 05:31
  • One of the great things about `ember-auto-import` is that it converts the dynamic import into working code on all the browsers in your `config/targets.js` file. The dynamic imports get transpiled out so that they work in everything your app supports. – jrjohnson Jan 09 '20 at 18:37