Cloudflare DevelopersCD
Cloudflare Developers2y ago
2 replies
sten

How to serve javascript files (as third party lib)

I am currently implementing a widget to be embedded as a third party library on websites.
I am developing it with Vanilla Svelte and rollup.js.

This is my rollup config.
export default {
input: 'src/embed.ts',
output: [
  {
    name: 'widget',
    format: 'iife',
    file: './dist/widget.js',
    sourcemap: true
  },
  {
    file: './dist/bundle.min.js',
    format: 'iife',
    name: 'version',
    plugins: [terser()]
  }
],
plugins: [
  json(),
  svelte({ preprocess: sveltePreprocess(), emitCss: false }),
  resolve({ browser: true, dedupe: ['svelte'] }),
  commonjs(),
  typescript({ sourceMap: true, inlineSources: false, exclude: ['main.ts'] })
]
};


Question: how can I serve the bundle.min.js through Cloudflare as a CDN? I am assuming it should be possible with Pages Direct Upload?

Idea is to be able to include the script like this later on:

 <script src="CDN.../bundle.min.js" defer></script> 


Would be awesome if someone could point me in the right direction
Was this page helpful?