Skip to content
Discussion options

You must be logged in to vote

I find two ways to use cdn in vite, wish can help you and others.

  1. If you build esm format output, you can use external and output.paths to include CDN module. Note that the CDN js must be a esm format js. And import ** from 'moduleName' will be replace with import ** from 'CDN_url'
    example:
// vite.config.js
  build: {
    rollupOptions: {
      external: ['vue'],
      output: {
        paths: {
          vue: 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
        }
      }
    }
  }
  1. If you build 'iife' or 'umd' format output, you can use external and output.globals to include CDN module. Note that the CDN js must export module to a global variable.
    example:
<!-- index.html -->
<!…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@erlangera
Comment options

@Hideman85
Comment options

@erlangera
Comment options

@shurintou
Comment options

@PeterlitsZo
Comment options

Answer selected by PeterlitsZo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants