vue.config.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const CopyWebpackPlugin = require('copy-webpack-plugin')
  5. function resolve(dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. const name = defaultSettings.title // 网址标题
  9. const port = 6112 // 端口配置
  10. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  11. module.exports = {
  12. // hash 模式下可使用
  13. //publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  14. publicPath: './',
  15. outputDir: 'dist',
  16. assetsDir: 'static',
  17. lintOnSave: process.env.NODE_ENV === 'development',
  18. productionSourceMap: false,
  19. devServer: {
  20. port: port,
  21. open: true,
  22. overlay: {
  23. warnings: false,
  24. errors: true
  25. },
  26. proxy: {
  27. '/api': {
  28. target: process.env.VUE_APP_BASE_API,
  29. changeOrigin: true,
  30. pathRewrite: {
  31. '^/api': 'api'
  32. }
  33. },
  34. '/auth': {
  35. target: process.env.VUE_APP_BASE_API,
  36. changeOrigin: true,
  37. pathRewrite: {
  38. '^/auth': 'auth'
  39. }
  40. }
  41. }
  42. },
  43. configureWebpack: {
  44. // provide the app's title in webpack's name field, so that
  45. // it can be accessed in index.html to inject the correct title.
  46. plugins: [
  47. new CopyWebpackPlugin([{
  48. from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer.swf',
  49. to: './libs/EasyPlayer/'
  50. },
  51. {
  52. from: 'node_modules/@easydarwin/easyplayer/dist/component/crossdomain.xml',
  53. to: './libs/EasyPlayer/'
  54. },
  55. {
  56. from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer-lib.min.js',
  57. to: './libs/EasyPlayer/'
  58. }
  59. ])
  60. ],
  61. name: name,
  62. resolve: {
  63. alias: {
  64. '@': resolve('src'),
  65. '@crud': resolve('src/components/Crud')
  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/assets/icons'))
  76. .end()
  77. config.module
  78. .rule('icons')
  79. .test(/\.svg$/)
  80. .include.add(resolve('src/assets/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',
  101. config => config.devtool('cheap-source-map')
  102. )
  103. config
  104. .when(process.env.NODE_ENV !== 'development',
  105. config => {
  106. config
  107. .plugin('ScriptExtHtmlWebpackPlugin')
  108. .after('html')
  109. .use('script-ext-html-webpack-plugin', [{
  110. // `runtime` must same as runtimeChunk name. default is `runtime`
  111. inline: /runtime\..*\.js$/
  112. }])
  113. .end()
  114. config
  115. .optimization.splitChunks({
  116. chunks: 'all',
  117. cacheGroups: {
  118. libs: {
  119. name: 'chunk-libs',
  120. test: /[\\/]node_modules[\\/]/,
  121. priority: 10,
  122. chunks: 'initial' // only package third parties that are initially dependent
  123. },
  124. elementUI: {
  125. name: 'chunk-elementUI', // split elementUI into a single package
  126. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  127. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  128. },
  129. commons: {
  130. name: 'chunk-commons',
  131. test: resolve('src/components'), // can customize your rules
  132. minChunks: 3, // minimum common number
  133. priority: 5,
  134. reuseExistingChunk: true
  135. }
  136. }
  137. })
  138. config.optimization.runtimeChunk('single')
  139. }
  140. )
  141. },
  142. transpileDependencies: [
  143. 'vue-echarts',
  144. 'resize-detector'
  145. ]
  146. }