vue.config.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 = 'http://api.shop.hzghd.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 = `http://img.hzghd.com/`;
  14. }else if(process.env.NODE_ENV == 'local'){
  15. hostUrl = `http://img.hzghd.com/`;
  16. }else{
  17. hostUrl = `https://img.hzghd.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. // additionalData: `@import "~@/assets/css/base.scss";`
  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: false
  74. },
  75. proxy: {
  76. '/dev': {
  77. target: proxyTarget,
  78. changeOrigin: true,
  79. pathRewrite: { '^/dev': '' }
  80. },
  81. '/s-dev': {
  82. target: proxyTarget,
  83. changeOrigin: true,
  84. pathRewrite: { '^/s-dev': '' }
  85. },
  86. '/pro': {
  87. target: proxyTarget,
  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')
  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. extract: false
  110. });
  111. // 去掉元素之间空格
  112. config.module
  113. .rule('vue')
  114. .use('vue-loader')
  115. .loader('vue-loader')
  116. .tap(options => {
  117. options.compilerOptions.preserveWhitespace = true;
  118. return options;
  119. })
  120. .end();
  121. // 引入cdn
  122. config.plugin('html').tap(args => {
  123. args[0].cdn = cdn[isProduction ? 'pro' : 'dev'];
  124. return args;
  125. });
  126. if (isProduction) {
  127. config.performance.set('hints', false);
  128. config.optimization.splitChunks({
  129. chunks: 'all',
  130. cacheGroups: {
  131. libs: {
  132. name: 'chunk-libs',
  133. test: /[\\/]node_modules[\\/]/,
  134. priority: 10,
  135. chunks: 'initial'
  136. },
  137. commons: {
  138. name: 'chunk-cool',
  139. test: resolve('src/cool'),
  140. minChunks: 3,
  141. priority: 5,
  142. reuseExistingChunk: true
  143. }
  144. }
  145. });
  146. }
  147. },
  148. configureWebpack: config => {
  149. if (isProduction) {
  150. config.externals = {
  151. vue: 'Vue',
  152. 'vue-router': 'VueRouter',
  153. 'element-ui': 'ELEMENT',
  154. vuex: 'Vuex',
  155. axios: 'axios',
  156. mockjs: 'Mock',
  157. nprogress: 'NProgress',
  158. quill: 'Quill',
  159. viewer: 'Viewer',
  160. echarts: 'echarts',
  161. 'vue-echarts': 'VueECharts'
  162. };
  163. }
  164. }
  165. };