vue.config.js 3.7 KB

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