vue.config.js 3.6 KB

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