vue.config.js 4.0 KB

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