vue.config.js 3.9 KB

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