vue.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const path = require('path');
  2. const isProduction = process.env.NODE_ENV === 'production';
  3. function resolve(dir) {
  4. return path.join(__dirname, dir);
  5. }
  6. const cdn = {
  7. dev: {
  8. css: ['https://cdn.bootcss.com/element-ui/2.13.0/theme-chalk/index.css']
  9. },
  10. pro: {
  11. css: [
  12. 'https://cdn.bootcss.com/nprogress/0.2.0/nprogress.min.css',
  13. 'https://cdn.bootcss.com/quill/2.0.0-dev.3/quill.core.min.css',
  14. 'https://cdn.bootcss.com/viewerjs/1.3.7/viewer.min.css',
  15. 'https://cdn.bootcss.com/element-ui/2.13.0/theme-chalk/index.css'
  16. ],
  17. js: [
  18. 'https://cdn.bootcss.com/vue/2.6.10/vue.min.js',
  19. 'https://cdn.bootcss.com/vue-router/3.1.3/vue-router.min.js',
  20. 'https://cdn.bootcss.com/vuex/3.1.1/vuex.min.js',
  21. 'https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js',
  22. 'https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.min.js',
  23. 'https://cdn.bootcss.com/nprogress/0.2.0/nprogress.min.js',
  24. 'https://cdn.bootcss.com/Mock.js/1.0.1-beta3/mock-min.js',
  25. 'https://cdn.bootcss.com/quill/2.0.0-dev.3/quill.min.js',
  26. 'https://cdn.bootcss.com/element-ui/2.13.0/index.js',
  27. 'https://cdn.bootcss.com/viewerjs/1.3.7/viewer.min.js',
  28. 'https://cdn.bootcss.com/echarts/4.4.0-rc.1/echarts.min.js',
  29. 'https://cdn.jsdelivr.net/npm/vue-echarts@4.0.2'
  30. ]
  31. }
  32. };
  33. module.exports = {
  34. publicPath: '/',
  35. lintOnSave: true,
  36. productionSourceMap: false,
  37. parallel: require('os').cpus().length > 1,
  38. css: {
  39. extract: isProduction,
  40. sourceMap: false,
  41. loaderOptions: {
  42. stylus: {
  43. import: '~@/assets/css/common.styl'
  44. },
  45. sass: {
  46. prependData: `@import "~@/assets/css/base.scss";`
  47. }
  48. }
  49. },
  50. devServer: {
  51. port: 7777,
  52. open: false,
  53. compress: false,
  54. overlay: {
  55. warnings: false,
  56. errors: true
  57. },
  58. proxy: {
  59. '/dev': {
  60. target: 'http://api.b.huaml.com',
  61. changeOrigin: true,
  62. pathRewrite: { '^/dev': '' }
  63. },
  64. '/pro': {
  65. target: 'http://api.b.huaml.com',
  66. changeOrigin: true,
  67. pathRewrite: { '^/pro': '/api' }
  68. }
  69. }
  70. },
  71. chainWebpack: config => {
  72. // svg
  73. config.module.rule('svg').uses.clear();
  74. config.module
  75. .rule('svg-sprite-loader')
  76. .test(/.svg$/)
  77. .exclude.add(/node_modules/)
  78. .end()
  79. .use('svg-sprite-loader')
  80. .loader('svg-sprite-loader')
  81. .options({
  82. symbolId: '[name]'
  83. });
  84. // 去掉元素之间空格
  85. config.module
  86. .rule('vue')
  87. .use('vue-loader')
  88. .loader('vue-loader')
  89. .tap(options => {
  90. options.compilerOptions.preserveWhitespace = true;
  91. return options;
  92. })
  93. .end();
  94. // 引入cdn
  95. config.plugin('html').tap(args => {
  96. args[0].cdn = cdn[isProduction ? 'pro' : 'dev'];
  97. return args;
  98. });
  99. if (isProduction) {
  100. config.performance.set('hints', false);
  101. config.optimization.splitChunks({
  102. chunks: 'all',
  103. cacheGroups: {
  104. libs: {
  105. name: 'chunk-libs',
  106. test: /[\\/]node_modules[\\/]/,
  107. priority: 10,
  108. chunks: 'initial'
  109. },
  110. commons: {
  111. name: 'chunk-cool',
  112. test: resolve('src/cool'),
  113. minChunks: 3,
  114. priority: 5,
  115. reuseExistingChunk: true
  116. }
  117. }
  118. });
  119. }
  120. },
  121. configureWebpack: config => {
  122. if (isProduction) {
  123. config.externals = {
  124. vue: 'Vue',
  125. 'vue-router': 'VueRouter',
  126. 'element-ui': 'ELEMENT',
  127. vuex: 'Vuex',
  128. axios: 'axios',
  129. mockjs: 'Mock',
  130. nprogress: 'NProgress',
  131. quill: 'Quill',
  132. viewer: 'Viewer',
  133. echarts: 'echarts',
  134. 'vue-echarts': 'VueECharts'
  135. };
  136. }
  137. }
  138. };