question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Locale Files as UMD or Browser Injectable Bundle

See original GitHub issue

In an application where users may have or switch to different locales, locale file should be in a format that can be injected with a script tag to the DOM. Like:

<script src="/js/dayjs-locales/en.umd.js" id="dayjs-locale-en"></script>

apart from solutions like dynamic import provided by webpack.

I achieved this once by coding a precompiler which transforms each locale file to a umd bundle but it was so fragile against library updates and turned back to import all locales to main build solution.

With proper bundling, we may inject and remove locale files at runtime, easily.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
iamkuncommented, Dec 24, 2019

load and invoke the locale file

How do you mean invoke ?

Load this via script element https://unpkg.com/dayjs/locale/uk, then you can use dayjs.locale('uk')

var script = document.createElement('script');
script.onload = function() {
  dayjs.locale('uk')
};
script.src = "https://unpkg.com/dayjs/locale/uk";
document.head.appendChild(script);
1reaction
iamkuncommented, Dec 24, 2019

@iamkun , If you like the index.js idea. Can I implement the same in dayjs? Ready to make a PR soon

That would be nice, please!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundle Angular 2 app using UMD bundles (not building ...
I have to use a module loader, and it doesn't look like WebPack has one that will work for this. To assign UMD...
Read more >
The JavaScript Modules Handbook – Complete Guide to ES ...
A module bundler is a tool developers use to bundle an app's modules and dependencies into a single browser-compatible JavaScript file. Why Do ......
Read more >
How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
Learn how to use Rollup as a smaller, more efficient alternative to webpack and Browserify to bundle JavaScript files in this step-by-step tutorial...
Read more >
Building for Production - Vite
The production bundle assumes support for modern JavaScript. By default, Vite targets browsers which support the native ES Modules, native ESM dynamic import, ......
Read more >
microbundle - npm
Microbundle produces esm , cjs , umd bundles with your code compiled to syntax that works pretty much everywhere. While it's possible to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found