vue.config.js 3.8 KB

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