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.

97 lines
3.7 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. publicPath: './',
  9. outputDir: 'dist',
  10. assetsDir: 'static',
  11. lintOnSave: process.env.NODE_ENV === 'development',
  12. productionSourceMap: false,
  13. devServer: {
  14. port: 8080,
  15. open: true,
  16. overlay: {
  17. warnings: false,
  18. errors: true
  19. },
  20. proxy: {
  21. // 把key的路径代理到target位置
  22. // detail: https://cli.vuejs.org/config/#devserver-proxy
  23. [process.env.VUE_APP_BASE_API]: { //需要代理的路径 例如 '/api'
  24. target: `http://127.0.0.1:8888`, //代理到 目标路径
  25. changeOrigin: true,
  26. pathRewrite: { // 修改路径数据
  27. ['^' + process.env.VUE_APP_BASE_API]: '' // 举例 '^/api:""' 把路径中的/api字符串删除
  28. }
  29. }
  30. },
  31. },
  32. configureWebpack: {
  33. // @路径走src文件夹
  34. resolve: {
  35. alias: {
  36. '@': resolve('src')
  37. }
  38. }
  39. },
  40. chainWebpack(config) {
  41. // set preserveWhitespace
  42. config.module
  43. .rule('vue')
  44. .use('vue-loader')
  45. .loader('vue-loader')
  46. .tap(options => {
  47. options.compilerOptions.preserveWhitespace = true
  48. return options
  49. })
  50. .end()
  51. config
  52. // https://webpack.js.org/configuration/devtool/#development
  53. .when(process.env.NODE_ENV === 'development',
  54. config => config.devtool('cheap-source-map')
  55. )
  56. config
  57. .when(process.env.NODE_ENV !== 'development',
  58. config => {
  59. config
  60. .plugin('ScriptExtHtmlWebpackPlugin')
  61. .after('html')
  62. .use('script-ext-html-webpack-plugin', [{
  63. // `runtime` must same as runtimeChunk name. default is `runtime`
  64. inline: /runtime\..*\.js$/
  65. }])
  66. .end()
  67. config
  68. .optimization.splitChunks({
  69. chunks: 'all',
  70. cacheGroups: {
  71. libs: {
  72. name: 'chunk-libs',
  73. test: /[\\/]node_modules[\\/]/,
  74. priority: 10,
  75. chunks: 'initial' // only package third parties that are initially dependent
  76. },
  77. elementUI: {
  78. name: 'chunk-elementUI', // split elementUI into a single package
  79. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  80. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  81. },
  82. commons: {
  83. name: 'chunk-commons',
  84. test: resolve('src/components'), // can customize your rules
  85. minChunks: 3, // minimum common number
  86. priority: 5,
  87. reuseExistingChunk: true
  88. }
  89. }
  90. })
  91. config.optimization.runtimeChunk('single')
  92. }
  93. )
  94. }
  95. }