vue.config.js 3.9 KB

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