vue.config.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. const path = require('path');
  2. // const getFirstHost = () => {
  3. // let host = window.location.host;
  4. // host = host.split('.');
  5. // host = host.length == 3 ? host[1] : host[0];
  6. // return process.env.NODE_ENV == 'development' ? 'huaml' : host;
  7. // };
  8. const isProduction = process.env.NODE_ENV === 'production';
  9. function resolve(dir) {
  10. return path.join(__dirname, dir);
  11. }
  12. // const hostUrl = `${window.location.protocol}//static.${getFirstHost()}.com`;
  13. // const hostUrl = `https://static.huaml.com`;
  14. const hostUrl = ``;
  15. const cdn = {
  16. dev: {
  17. css: [`https://cdn.bootcss.com/element-ui/2.13.0/theme-chalk/index.css`]
  18. },
  19. pro: {
  20. css: [
  21. `${hostUrl}/cdn/nprogress/0.2.0/nprogress.min.css`,
  22. `${hostUrl}/cdn/quill/2.0.0-dev.3/quill.core.min.css`,
  23. `${hostUrl}/cdn/viewerjs/1.3.7/viewer.min.css`,
  24. `${hostUrl}/cdn/element-ui/2.13.0/theme-chalk/index.css`
  25. ],
  26. js: [
  27. `${hostUrl}/cdn/vue/2.6.10/vue.min.js`,
  28. `${hostUrl}/cdn/vue-router/3.1.3/vue-router.min.js`,
  29. `${hostUrl}/cdn/vuex/3.1.1/vuex.min.js`,
  30. `${hostUrl}/cdn/clipboard.js/2.0.4/clipboard.min.js`,
  31. `${hostUrl}/cdn/axios/0.19.0-beta.1/axios.min.js`,
  32. `${hostUrl}/cdn/nprogress/0.2.0/nprogress.min.js`,
  33. `${hostUrl}/cdn/Mock.js/1.0.1-beta3/mock-min.js`,
  34. `${hostUrl}/cdn/quill/2.0.0-dev.3/quill.min.js`,
  35. `${hostUrl}/cdn/element-ui/2.13.0/index.js`,
  36. `${hostUrl}/cdn/viewerjs/1.3.7/viewer.min.js`,
  37. `${hostUrl}/cdn/echarts/4.4.0-rc.1/echarts.min.js`,
  38. `${hostUrl}/cdn/npm/vue-echarts@4.0.2.js`
  39. // https://cdn.bootcss.com
  40. // 'https://cdn.jsdelivr.net/npm/vue-echarts@4.0.2'
  41. ]
  42. }
  43. };
  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: 'http://api.shop.huaml.com',
  75. changeOrigin: true,
  76. pathRewrite: { '^/dev': '' }
  77. },
  78. '/s-dev': {
  79. target: 'http://api.shop.huaml.com',
  80. changeOrigin: true,
  81. pathRewrite: { '^/s-dev': '' }
  82. },
  83. '/pro': {
  84. target: 'http://api.shop.huaml.com',
  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. };