vue.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const cdn = {
  2. // 开发环境
  3. dev: {
  4. css: [],
  5. js: [],
  6. },
  7. // 生产环境
  8. build: {
  9. css: [
  10. //'//unpkg.com/element-plus@2.3.7/theme-chalk/index.css'
  11. ],
  12. js: [
  13. //最好限定版本号
  14. // '//unpkg.com/vue@3',
  15. // '//unpkg.com/vuex',
  16. // '//unpkg.com/element-plus',
  17. // '//unpkg.com/vue-router',
  18. // '//unpkg.com/axios',
  19. // '//unpkg.com/@element-plus/icons-vue'
  20. ],
  21. },
  22. };
  23. // externals
  24. const externals = {
  25. // vue: 'Vue',
  26. // 'vue-router': 'VueRouter',
  27. // vuex: 'Vuex',
  28. // 'element-plus': 'ElementPlus',
  29. // axios: 'axios',
  30. // '@element-plus/icons-vue': 'ElementPlusIconsVue'
  31. };
  32. const fs = require('fs');
  33. const path = require('path');
  34. module.exports = {
  35. configureWebpack: (config) => {
  36. // 为生产环境修改配置...
  37. if (process.env.NODE_ENV === 'production') {
  38. // externals 放置需要使用 cdn 的库
  39. config.externals = externals;
  40. config.mode = 'production';
  41. // 打包文件大小配置
  42. config.performance = {
  43. //入口起点的最大体积 默认值是:250000
  44. maxEntrypointSize: 50000000,
  45. //生成资源(asset)文件的最大体积
  46. maxAssetSize: 30000000,
  47. };
  48. }
  49. },
  50. devServer: {
  51. // allowedHosts: [
  52. // 'host.com', // 允许访问的域名地址,即花生壳内网穿透的地址
  53. // '.host.com' // .是二级域名的通配符
  54. // ],
  55. // 跳过检查host
  56. disableHostCheck: true,
  57. // https: { //https调试配置
  58. // key: fs.readFileSync(path.join(__dirname, 'localhost.key')),
  59. // cert: fs.readFileSync(path.join(__dirname, 'localhost.cert')),
  60. // },
  61. proxy: {
  62. '/api': {
  63. target: 'http://kaung.cn:7001',
  64. changeOrigin: true,
  65. pathRewrite: {
  66. '^/api': '',
  67. },
  68. },
  69. },
  70. },
  71. chainWebpack: (config) => {
  72. // 配置,将当前页定义的cdn值传到主页面(index.html)
  73. config.plugin('html').tap((args) => {
  74. // 这里我是除本地环境,其余均使用CDN,可自己选择是否配置
  75. if (process.env.NODE_ENV === 'production') {
  76. args[0].cdn = cdn.build;
  77. } else {
  78. args[0].cdn = cdn.dev;
  79. }
  80. //args[0].cdn = process.env.VUE_APP_STAGE === 'LOCAL' ? {} : CDN
  81. //args[0].cdn = CDN
  82. //args[0].title = this.$store.getters.getWebSetting.projectName; //"ERP综合管理系统";
  83. return args;
  84. });
  85. },
  86. // chainWebpack: (config) => {
  87. // // 通过 style-resources-loader 来添加less全局变量
  88. // const types = ['vue-modules', 'vue', 'normal-modules', 'normal'];
  89. // types.forEach(type => {
  90. // let rule = config.module.rule('less').oneOf(type)
  91. // rule.use('style-resource')
  92. // .loader('style-resources-loader')
  93. // .options({
  94. // patterns: [path.resolve(__dirname, './lessVariates.less')]
  95. // });
  96. // });
  97. // // // `svg-sprite-loader`: 将svg图片以雪碧图的方式在项目中加载
  98. // // config.module
  99. // // .rule('svg')
  100. // // .test(/\.svg$/) // 匹配svg文件
  101. // // .include.add(resolve('src/svg')) // 主要匹配src/svg
  102. // // .end()
  103. // // .use('svg-sprite-loader')
  104. // // .loader('svg-sprite-loader') // 使用的loader,主要要npm该插件
  105. // // .options({symbolId: 'svg-[name]'}) // 参数配置
  106. // }
  107. };