vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. config.devtool = 'source-map';
  50. },
  51. devServer: {
  52. // allowedHosts: [
  53. // 'host.com', // 允许访问的域名地址,即花生壳内网穿透的地址
  54. // '.host.com' // .是二级域名的通配符
  55. // ],
  56. // 跳过检查host
  57. disableHostCheck: true,
  58. // https: { //https调试配置
  59. // key: fs.readFileSync(path.join(__dirname, 'localhost.key')),
  60. // cert: fs.readFileSync(path.join(__dirname, 'localhost.cert')),
  61. // },
  62. proxy: {
  63. '/api': {
  64. // target: 'http://kaung.cn:7001',
  65. target: 'https://ljyx.hhtrip.com.cn',
  66. changeOrigin: true,
  67. pathRewrite: {
  68. '^/api': '',
  69. },
  70. },
  71. },
  72. },
  73. chainWebpack: (config) => {
  74. // 配置,将当前页定义的cdn值传到主页面(index.html)
  75. config.plugin('html').tap((args) => {
  76. // 这里我是除本地环境,其余均使用CDN,可自己选择是否配置
  77. if (process.env.NODE_ENV === 'production') {
  78. args[0].cdn = cdn.build;
  79. } else {
  80. args[0].cdn = cdn.dev;
  81. }
  82. //args[0].cdn = process.env.VUE_APP_STAGE === 'LOCAL' ? {} : CDN
  83. //args[0].cdn = CDN
  84. //args[0].title = this.$store.getters.getWebSetting.projectName; //"ERP综合管理系统";
  85. return args;
  86. });
  87. },
  88. // chainWebpack: (config) => {
  89. // // 通过 style-resources-loader 来添加less全局变量
  90. // const types = ['vue-modules', 'vue', 'normal-modules', 'normal'];
  91. // types.forEach(type => {
  92. // let rule = config.module.rule('less').oneOf(type)
  93. // rule.use('style-resource')
  94. // .loader('style-resources-loader')
  95. // .options({
  96. // patterns: [path.resolve(__dirname, './lessVariates.less')]
  97. // });
  98. // });
  99. // // // `svg-sprite-loader`: 将svg图片以雪碧图的方式在项目中加载
  100. // // config.module
  101. // // .rule('svg')
  102. // // .test(/\.svg$/) // 匹配svg文件
  103. // // .include.add(resolve('src/svg')) // 主要匹配src/svg
  104. // // .end()
  105. // // .use('svg-sprite-loader')
  106. // // .loader('svg-sprite-loader') // 使用的loader,主要要npm该插件
  107. // // .options({symbolId: 'svg-[name]'}) // 参数配置
  108. // }
  109. };