1
1
import randomstring from 'randomstring'
2
2
import { viteExternalsPlugin as ViteExternals } from 'vite-plugin-externals'
3
3
import { createHtmlPlugin } from 'vite-plugin-html'
4
- import { viteStaticCopy } from 'vite-plugin-static-copy'
5
4
import type { HtmlTagDescriptor } from 'vite'
6
- import type { Target } from 'vite-plugin-static-copy'
5
+
6
+ import { dependencies } from './package.json'
7
7
8
8
/**
9
9
* It copies the external libraries to the `assets` folder, and injects the script tags into the HTML
@@ -21,41 +21,37 @@ export const setupLibraryExternal = (
21
21
charset : 'hex' ,
22
22
} )
23
23
24
- const staticTargets : Target [ ] = [
24
+ const cdnUrl = 'https://unpkg.com/'
25
+
26
+ const staticTargets : { dev : string ; prod : string } [ ] = [
25
27
{
26
- src : `./node_modules/vue/dist/vue.global${
28
+ dev : `./node_modules/vue/dist/vue.global${
27
29
isProduction ? '.prod' : ''
28
30
} .js`,
29
- dest : './assets/vue' ,
30
- rename : `vue.global.${ staticSuffix } .js` ,
31
+ prod : `${ cdnUrl } vue@${ dependencies . vue } /dist/vue.global.prod.js` ,
31
32
} ,
32
33
{
33
- src : `./node_modules/vue-router/dist/vue-router.global${
34
+ dev : `./node_modules/vue-router/dist/vue-router.global${
34
35
isProduction ? '.prod' : ''
35
36
} .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` ,
38
38
} ,
39
39
40
40
{
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 } [email protected] /lib/index.iife.js` ,
44
43
} ,
45
44
{
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` ,
49
47
} ,
50
48
{
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` ,
54
51
} ,
55
52
{
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` ,
59
55
} ,
60
56
]
61
57
@@ -65,9 +61,7 @@ export const setupLibraryExternal = (
65
61
injectTo : 'head' ,
66
62
tag : 'script' ,
67
63
attrs : {
68
- src : isProduction
69
- ? `${ baseUrl } ${ target . dest } /${ target . rename } `
70
- : target . src ,
64
+ src : isProduction ? target . prod : target . dev ,
71
65
type : 'text/javascript' ,
72
66
} ,
73
67
}
@@ -84,10 +78,7 @@ export const setupLibraryExternal = (
84
78
85
79
'vue-demi' : 'VueDemi' ,
86
80
} ) ,
87
- isProduction &&
88
- viteStaticCopy ( {
89
- targets : staticTargets ,
90
- } ) ,
81
+
91
82
createHtmlPlugin ( {
92
83
minify : false ,
93
84
inject : {
0 commit comments