vue.config-production.js 3.9 KB

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