You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.9 KiB

  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. module.exports = {
  7. /**
  8. * You will need to set publicPath if you plan to deploy your site under a sub path,
  9. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  10. * then publicPath should be set to "/bar/".
  11. * In most cases please use '/' !!!
  12. * Detail: https://cli.vuejs.org/config/#publicpath
  13. */
  14. publicPath: '/',
  15. outputDir: 'dist',
  16. assetsDir: 'static',
  17. lintOnSave: process.env.NODE_ENV === 'development',
  18. productionSourceMap: false,
  19. devServer: {
  20. port: 8080,
  21. open: true,
  22. overlay: {
  23. warnings: false,
  24. errors: true
  25. },
  26. proxy: {
  27. // change xxx-api/login => mock/login
  28. // detail: https://cli.vuejs.org/config/#devserver-proxy
  29. [process.env.VUE_APP_BASE_API]: {
  30. target: `http://127.0.0.1:8888`,
  31. changeOrigin: true,
  32. pathRewrite: {
  33. ['^' + process.env.VUE_APP_BASE_API]: ''
  34. }
  35. }
  36. },
  37. },
  38. configureWebpack: {
  39. // provide the app's title in webpack's name field, so that
  40. // it can be accessed in index.html to inject the correct title.
  41. resolve: {
  42. alias: {
  43. '@': resolve('src')
  44. }
  45. }
  46. },
  47. chainWebpack(config) {
  48. // set preserveWhitespace
  49. config.module
  50. .rule('vue')
  51. .use('vue-loader')
  52. .loader('vue-loader')
  53. .tap(options => {
  54. options.compilerOptions.preserveWhitespace = true
  55. return options
  56. })
  57. .end()
  58. config
  59. // https://webpack.js.org/configuration/devtool/#development
  60. .when(process.env.NODE_ENV === 'development',
  61. config => config.devtool('cheap-source-map')
  62. )
  63. config
  64. .when(process.env.NODE_ENV !== 'development',
  65. config => {
  66. config
  67. .plugin('ScriptExtHtmlWebpackPlugin')
  68. .after('html')
  69. .use('script-ext-html-webpack-plugin', [{
  70. // `runtime` must same as runtimeChunk name. default is `runtime`
  71. inline: /runtime\..*\.js$/
  72. }])
  73. .end()
  74. config
  75. .optimization.splitChunks({
  76. chunks: 'all',
  77. cacheGroups: {
  78. libs: {
  79. name: 'chunk-libs',
  80. test: /[\\/]node_modules[\\/]/,
  81. priority: 10,
  82. chunks: 'initial' // only package third parties that are initially dependent
  83. },
  84. elementUI: {
  85. name: 'chunk-elementUI', // split elementUI into a single package
  86. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  87. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  88. },
  89. commons: {
  90. name: 'chunk-commons',
  91. test: resolve('src/components'), // can customize your rules
  92. minChunks: 3, // minimum common number
  93. priority: 5,
  94. reuseExistingChunk: true
  95. }
  96. }
  97. })
  98. config.optimization.runtimeChunk('single')
  99. }
  100. )
  101. }
  102. }