topick icon indicating copy to clipboard operation
topick copied to clipboard

Not usable via CDN

Open kierans opened this issue 3 years ago • 4 comments

I have a Shopify site where I need to dynamically convert from a currency code to a symbol. However being in Shopify I can't use NPM modules.

I'm happy to do a PR for a webpack build so that this library can be used via a CDN.

kierans avatar Jan 17 '22 04:01 kierans

is there any solution?

official-akshayjadhav avatar Jun 02 '22 09:06 official-akshayjadhav

@official-akshayjadhav I used my webpack config to create a dist and added it to my Shopify site's assets as a JS file. Adding an include tag in the main template file saw the JS loaded which means I could use the module. However it would be better to have this module in a CDN.

kierans avatar Jun 02 '22 09:06 kierans

you can use skypack, which will transform this nicely for you: https://cdn.skypack.dev/currency-symbol-map

example invocation:

<script type="module">
    import getSymbolFromCurrency from 'https://cdn.skypack.dev/currency-symbol-map'

    const s = getSymbolFromCurrency('USD')
</script>

mreinstein avatar Jun 21 '22 16:06 mreinstein

you can use skypack, which will transform this nicely for you: https://cdn.skypack.dev/currency-symbol-map

example invocation:

<script type="module">
    import getSymbolFromCurrency from 'https://cdn.skypack.dev/currency-symbol-map'

    const s = getSymbolFromCurrency('USD')
</script>

Perfect, thank you so much! I was able to get it working with this (although I implemented it a bit differently).

I had made a file called globalModules.js:

import getSymbolFromCurrency from "https://cdn.skypack.dev/currency-symbol-map";

const Get_Currency_Symbol = (code) => {
	return getSymbolFromCurrency(code);
};

export { Get_Currency_Symbol };

I then imported this into another JS file, which was loaded in the HTML with the type="module" attribute:

import { Get_Currency_Symbol } from "./globalModules.js";

Then you directly use the function Get_Currency_Symbol().

Daniel-FDS avatar Nov 11 '22 09:11 Daniel-FDS