vue.config.js 4.3 KB

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