vue.config.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. 'use strict';
  2. const path = require('path');
  3. const defaultSettings = require('./src/settings.js');
  4. function resolve (dir) {
  5. return path.join(__dirname, dir);
  6. }
  7. const name = defaultSettings.title || '大雅报名管理'; // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following methods:
  12. // port = 9528 npm run dev OR npm run dev --port = 9528
  13. const port = process.env.port || process.env.npm_config_port || 9528; // dev port
  14. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  15. module.exports = {
  16. /**
  17. * You will need to set publicPath if you plan to deploy your site under a sub path,
  18. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  19. * then publicPath should be set to "/bar/".
  20. * In most cases please use '/' !!!
  21. * Detail: https://cli.vuejs.org/config/#publicpath
  22. */
  23. publicPath: './',
  24. outputDir: 'dist',
  25. assetsDir: 'static',
  26. lintOnSave: false,
  27. productionSourceMap: false,
  28. devServer: {
  29. // port: port,
  30. open: true,
  31. // overlay: {
  32. // warnings: false,
  33. // errors: true
  34. // },
  35. proxy: {
  36. // change xxx-api/login => mock/login
  37. // detail: https://cli.vuejs.org/config/#devserver-proxy
  38. // http://admin.dayaedu.com
  39. // http://192.168.3.27
  40. // http://192.168.3.28:8005
  41. // 192.168.3.38:8088
  42. '/order': {
  43. target: 'http://testpay.dayaedu.com',
  44. // target: `http://192.168.3.38:9000`,
  45. changeOrigin: true,
  46. pathRewrite: {
  47. "^order": ''
  48. }
  49. },
  50. '/user': {
  51. target: 'http://testpay.dayaedu.com',
  52. // target: `http://192.168.3.38:9000`,
  53. changeOrigin: true,
  54. pathRewrite: {
  55. "^user": ''
  56. }
  57. }
  58. },
  59. // after: require('./mock/mock-server.js')
  60. },
  61. configureWebpack: {
  62. // provide the app's title in webpack's name field, so that
  63. // it can be accessed in index.html to inject the correct title.
  64. name: name,
  65. resolve: {
  66. alias: {
  67. '@': resolve('src')
  68. }
  69. }
  70. },
  71. chainWebpack (config) {
  72. config.plugins.delete('preload'); // TODO: need test
  73. config.plugins.delete('prefetch'); // TODO: need test
  74. // set svg-sprite-loader
  75. config.module
  76. .rule('svg')
  77. .exclude.add(resolve('src/icons'))
  78. .end();
  79. config.module
  80. .rule('icons')
  81. .test(/\.svg$/)
  82. .include.add(resolve('src/icons'))
  83. .end()
  84. .use('svg-sprite-loader')
  85. .loader('svg-sprite-loader')
  86. .options({
  87. symbolId: 'icon-[name]'
  88. })
  89. .end();
  90. // set preserveWhitespace
  91. config.module
  92. .rule('vue')
  93. .use('vue-loader')
  94. .loader('vue-loader')
  95. .tap(options => {
  96. options.compilerOptions.preserveWhitespace = true;
  97. return options;
  98. })
  99. .end();
  100. config
  101. // https://webpack.js.org/configuration/devtool/#development
  102. .when(process.env.NODE_ENV === 'development', config =>
  103. config.devtool('cheap-source-map')
  104. );
  105. config.when(process.env.NODE_ENV !== 'development', config => {
  106. config
  107. .plugin('ScriptExtHtmlWebpackPlugin')
  108. .after('html')
  109. .use('script-ext-html-webpack-plugin', [
  110. {
  111. // `runtime` must same as runtimeChunk name. default is `runtime`
  112. inline: /runtime\..*\.js$/
  113. }
  114. ])
  115. .end();
  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' // only package third parties that are initially dependent
  124. },
  125. elementUI: {
  126. name: 'chunk-elementUI', // split elementUI into a single package
  127. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  128. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  129. },
  130. commons: {
  131. name: 'chunk-commons',
  132. test: resolve('src/components'), // can customize your rules
  133. minChunks: 3, // minimum common number
  134. priority: 5,
  135. reuseExistingChunk: true
  136. }
  137. }
  138. });
  139. config.optimization.runtimeChunk('single');
  140. });
  141. }
  142. };