vue.config-production.js 4.0 KB

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