vue.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. let hostUrl = 'https://img.hzghd.com/';
  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. // additionalData: `@import "~@/assets/css/base.scss";`
  52. prependData: `@import "~@/assets/css/base.scss";`
  53. }
  54. }
  55. },
  56. devServer: {
  57. host: '127.0.0.1',
  58. port: 7777,
  59. open: false,
  60. compress: false,
  61. overlay: {
  62. warnings: false,
  63. errors: false
  64. },
  65. proxy: {
  66. '/dev': {
  67. target: proxyTarget,
  68. changeOrigin: true,
  69. pathRewrite: { '^/dev': '' }
  70. },
  71. '/s-dev': {
  72. target: proxyTarget,
  73. changeOrigin: true,
  74. pathRewrite: { '^/s-dev': '' }
  75. },
  76. '/pro': {
  77. target: proxyTarget,
  78. changeOrigin: true,
  79. pathRewrite: { '^/pro': '/api' }
  80. }
  81. }
  82. },
  83. chainWebpack: config => {
  84. // 移除 prefetch 插件
  85. config.plugins.delete('prefetch');
  86. // 移除 preload 插件
  87. // config.plugins.delete('preload');
  88. // svg
  89. config.module.rule('svg').uses.clear();
  90. config.module
  91. .rule('svg-sprite')
  92. .test(/.svg$/)
  93. .exclude.add(/node_modules/)
  94. .end()
  95. .use('svg-sprite-loader')
  96. .loader('svg-sprite-loader')
  97. .options({
  98. symbolId: '[name]',
  99. extract: false
  100. });
  101. // 去掉元素之间空格
  102. config.module
  103. .rule('vue')
  104. .use('vue-loader')
  105. .loader('vue-loader')
  106. .tap(options => {
  107. options.compilerOptions.preserveWhitespace = true;
  108. return options;
  109. })
  110. .end();
  111. // 引入cdn
  112. config.plugin('html').tap(args => {
  113. args[0].cdn = cdn[isProduction ? 'pro' : 'dev'];
  114. return args;
  115. });
  116. if (isProduction) {
  117. config.performance.set('hints', false);
  118. config.optimization.splitChunks({
  119. chunks: 'all',
  120. cacheGroups: {
  121. libs: {
  122. name: 'chunk-libs',
  123. test: /[\\/]node_modules[\\/]/,
  124. priority: 10,
  125. chunks: 'initial'
  126. },
  127. commons: {
  128. name: 'chunk-cool',
  129. test: resolve('src/cool'),
  130. minChunks: 3,
  131. priority: 5,
  132. reuseExistingChunk: true
  133. }
  134. }
  135. });
  136. }
  137. },
  138. configureWebpack: config => {
  139. if (isProduction) {
  140. config.externals = {
  141. vue: 'Vue',
  142. 'vue-router': 'VueRouter',
  143. 'element-ui': 'ELEMENT',
  144. vuex: 'Vuex',
  145. axios: 'axios',
  146. mockjs: 'Mock',
  147. nprogress: 'NProgress',
  148. quill: 'Quill',
  149. viewer: 'Viewer',
  150. echarts: 'echarts',
  151. 'vue-echarts': 'VueECharts'
  152. };
  153. }
  154. }
  155. };