vue.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict';
  2. /*
  3. * @Description: In User Settings Edit
  4. * @Author: your name
  5. * @Date: 2019-09-15 19:43:39
  6. * @LastEditTime: 2019-09-15 19:43:39
  7. * @LastEditors: your name
  8. */
  9. /**
  10. * 自定义输入方式
  11. * @type {String}
  12. */
  13. const outputDir = 'web';
  14. const isProduction = process.env.NODE_ENV === 'production';
  15. const cdn = {
  16. css: [],
  17. js: [
  18. 'https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.js',
  19. 'https://cdn.bootcdn.net/ajax/libs/vue-router/3.2.0/vue-router.js',
  20. 'https://cdn.bootcdn.net/ajax/libs/vuex/3.5.1/vuex.min.js',
  21. 'https://cdn.bootcdn.net/ajax/libs/element-ui/2.13.2/index.js',
  22. 'https://cdn.bootcdn.net/ajax/libs/qs/6.9.4/qs.js',
  23. 'https://cdn.bootcdn.net/ajax/libs/axios/0.20.0/axios.js',
  24. 'https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js'
  25. ],
  26. externals:{
  27. vue:'Vue',
  28. 'vue-router':'VueRouter',
  29. 'element-ui':'ELEMENT',
  30. axios:'axios',
  31. vuex:'Vuex',
  32. echarts:'echarts',
  33. qs:'Qs'
  34. }
  35. }
  36. module.exports = {
  37. publicPath: isProduction ? './': '/',
  38. devServer: {
  39. port: 8080,
  40. proxy: {
  41. '/apis': {
  42. target: isProduction ?'http://192.168.1.222:8105':'http://192.168.1.222:8105',
  43. ws: true, // proxy websockets
  44. changeOrigin: true, // needed for virtual hosted sites
  45. pathRewrite: {
  46. '^/apis': '/' // rewrite path
  47. }
  48. }
  49. },
  50. disableHostCheck: true
  51. },
  52. //关闭语法检查
  53. lintOnSave:false,
  54. //生产环境是否生成 sourceMap 文件
  55. productionSourceMap:false,
  56. //输出文件目录
  57. outputDir:outputDir,
  58. // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径
  59. configureWebpack: config => {
  60. if(isProduction) config.externals = cdn.externals;
  61. },
  62. chainWebpack: config => {
  63. // 生产环境配置
  64. if (isProduction) {
  65. // 删除预加载
  66. config.plugins.delete('preload');
  67. config.plugins.delete('prefetch');
  68. //压缩代码
  69. config.optimization.minimize(true);
  70. // 分割代码
  71. config.optimization.splitChunks({
  72. chunks: 'all'
  73. })
  74. //生产环境注入cdn
  75. config.plugin('html').tap(args => {
  76. args[0].cdn = cdn;
  77. return args;
  78. });
  79. }
  80. },
  81. };