vue.config.js 3.8 KB

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