build plugin
esmCdn({
sleep:1000, // Waiting for module collection, may have a higher value
cdn:'npmmirror',
modules:['vue','vue-router'],
})
npm i unplugin-esm-cdn -d
Vite
// vite.config.ts
import esmCdn from 'unplugin-esm-cdn/vite'
export default defineConfig({
plugins: [
esmCdn({ /* options */ }),
],
})
Example: playground/
Rollup
// rollup.config.js
import esmCdn from 'unplugin-esm-cdn/rollup'
export default {
plugins: [
esmCdn({ /* options */ }),
],
}
Webpack
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-esm-cdn/webpack')({ /* options */ })
]
}
Nuxt
// nuxt.config.js
export default defineNuxtConfig({
modules: [
['unplugin-esm-cdn/nuxt', { /* options */ }],
],
})
This module works for both Nuxt 2 and Nuxt Vite
Vue CLI
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-esm-cdn/webpack')({ /* options */ }),
],
},
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'
import esmCdn from 'unplugin-esm-cdn/esbuild'
build({
plugins: [esmCdn()],
})