vue.config-production.js 3.8 KB

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