cdn.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { Plugin as importToCDN } from "vite-plugin-cdn-import";
  2. /**
  3. * @description 打包时采用`cdn`模式,仅限外网使用(默认不采用,如果需要采用cdn模式,请在 .env.production 文件,将 VITE_CDN 设置成true)
  4. * 平台采用国内cdn:https://www.bootcdn.cn,当然你也可以选择 https://unpkg.com 或者 https://www.jsdelivr.com
  5. * 注意:上面提到的仅限外网使用也不是完全肯定的,如果你们公司内网部署的有相关js、css文件,也可以将下面配置对应改一下,整一套内网版cdn
  6. */
  7. export const cdn = importToCDN({
  8. //(prodUrl解释: name: 对应下面modules的name,version: 自动读取本地package.json中dependencies依赖中对应包的版本号,path: 对应下面modules的path,当然也可写完整路径,会替换prodUrl)
  9. prodUrl: "https://cdn.bootcdn.net/ajax/libs/{name}/{version}/{path}",
  10. modules: [
  11. {
  12. name: "vue",
  13. var: "Vue",
  14. path: "vue.global.prod.min.js"
  15. },
  16. {
  17. name: "vue-router",
  18. var: "VueRouter",
  19. path: "vue-router.global.min.js"
  20. },
  21. // 项目中没有直接安装vue-demi,但是pinia用到了,所以需要在引入pinia前引入vue-demi(https://github.com/vuejs/pinia/blob/v2/packages/pinia/package.json#L77)
  22. {
  23. name: "vue-demi",
  24. var: "VueDemi",
  25. path: "index.iife.min.js"
  26. },
  27. {
  28. name: "pinia",
  29. var: "Pinia",
  30. path: "pinia.iife.min.js"
  31. },
  32. {
  33. name: "element-plus",
  34. var: "ElementPlus",
  35. path: "index.full.min.js",
  36. css: "index.min.css"
  37. },
  38. {
  39. name: "axios",
  40. var: "axios",
  41. path: "axios.min.js"
  42. },
  43. {
  44. name: "dayjs",
  45. var: "dayjs",
  46. path: "dayjs.min.js"
  47. },
  48. {
  49. name: "echarts",
  50. var: "echarts",
  51. path: "echarts.min.js"
  52. }
  53. ]
  54. });