11import randomstring from 'randomstring'
22import { viteExternalsPlugin as ViteExternals } from 'vite-plugin-externals'
33import { createHtmlPlugin } from 'vite-plugin-html'
4- import { viteStaticCopy } from 'vite-plugin-static-copy'
54import type { HtmlTagDescriptor } from 'vite'
6- import type { Target } from 'vite-plugin-static-copy'
5+
6+ import { dependencies } from './package.json'
77
88/**
99 * It copies the external libraries to the `assets` folder, and injects the script tags into the HTML
@@ -21,41 +21,37 @@ export const setupLibraryExternal = (
2121 charset : 'hex' ,
2222 } )
2323
24- const staticTargets : Target [ ] = [
24+ const cdnUrl = 'https://unpkg.com/'
25+
26+ const staticTargets : { dev : string ; prod : string } [ ] = [
2527 {
26- src : `./node_modules/vue/dist/vue.global${
28+ dev : `./node_modules/vue/dist/vue.global${
2729 isProduction ? '.prod' : ''
2830 } .js`,
29- dest : './assets/vue' ,
30- rename : `vue.global.${ staticSuffix } .js` ,
31+ prod : `${ cdnUrl } vue@${ dependencies . vue } /dist/vue.global.prod.js` ,
3132 } ,
3233 {
33- src : `./node_modules/vue-router/dist/vue-router.global${
34+ dev : `./node_modules/vue-router/dist/vue-router.global${
3435 isProduction ? '.prod' : ''
3536 } .js`,
36- dest : './assets/vue-router' ,
37- rename : `vue-router.global.${ staticSuffix } .js` ,
37+ prod : `${ cdnUrl } vue-router@${ dependencies [ 'vue-router' ] } /dist/vue-router.global.prod.js` ,
3838 } ,
3939
4040 {
41- src : `./node_modules/vue-demi/lib/index.iife.js` ,
42- dest : './assets/vue-demi' ,
43- rename : `vue-demi.${ staticSuffix } .js` ,
41+ dev : `./node_modules/vue-demi/lib/index.iife.js` ,
42+ prod : `${ cdnUrl } vue-demi@0.14.6/lib/index.iife.js` ,
4443 } ,
4544 {
46- src : './node_modules/@vueuse/shared/index.iife.min.js' ,
47- dest : './assets/vueuse' ,
48- rename : `vueuse.shared.iife.${ staticSuffix } .js` ,
45+ dev : './node_modules/@vueuse/shared/index.iife.min.js' ,
46+ prod : `${ cdnUrl } @vueuse/shared@${ dependencies [ '@vueuse/shared' ] } /index.iife.min.js` ,
4947 } ,
5048 {
51- src : './node_modules/@vueuse/core/index.iife.min.js' ,
52- dest : './assets/vueuse' ,
53- rename : `vueuse.core.iife.${ staticSuffix } .js` ,
49+ dev : './node_modules/@vueuse/core/index.iife.min.js' ,
50+ prod : `${ cdnUrl } @vueuse/core@${ dependencies [ '@vueuse/core' ] } /index.iife.min.js` ,
5451 } ,
5552 {
56- src : './node_modules/@vueuse/components/index.iife.min.js' ,
57- dest : './assets/vueuse' ,
58- rename : `vueuse.components.iife.${ staticSuffix } .js` ,
53+ dev : './node_modules/@vueuse/components/index.iife.min.js' ,
54+ prod : `${ cdnUrl } @vueuse/components@${ dependencies [ '@vueuse/components' ] } /index.iife.min.js` ,
5955 } ,
6056 ]
6157
@@ -65,9 +61,7 @@ export const setupLibraryExternal = (
6561 injectTo : 'head' ,
6662 tag : 'script' ,
6763 attrs : {
68- src : isProduction
69- ? `${ baseUrl } ${ target . dest } /${ target . rename } `
70- : target . src ,
64+ src : isProduction ? target . prod : target . dev ,
7165 type : 'text/javascript' ,
7266 } ,
7367 }
@@ -84,10 +78,7 @@ export const setupLibraryExternal = (
8478
8579 'vue-demi' : 'VueDemi' ,
8680 } ) ,
87- isProduction &&
88- viteStaticCopy ( {
89- targets : staticTargets ,
90- } ) ,
81+
9182 createHtmlPlugin ( {
9283 minify : false ,
9384 inject : {
0 commit comments