vue.config.js 3.7 KB

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