vue.config.js 4.3 KB

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