飞天云平台-国产化
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.

170 lines
4.9 KiB

3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
  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 // 网址标题
  8. const port = 8018 // 端口配置
  9. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  10. // const GenerateAssetPlugin = require('generate-asset-webpack-plugin')
  11. // const createServerConfig = compilation => {
  12. // const serverConfig = {
  13. // BASE_URL: '' // 打包后生成的文件内容,接口地址
  14. // }
  15. // return JSON.stringify(serverConfig)
  16. // }
  17. module.exports = {
  18. // hash 模式下可使用
  19. publicPath: process.env.NODE_ENV === 'development' ? '/' : './',
  20. // publicPath: '/',
  21. outputDir: 'dist',
  22. assetsDir: 'static',
  23. lintOnSave: process.env.NODE_ENV === 'development',
  24. productionSourceMap: false,
  25. devServer: {
  26. // https: {
  27. // // 读取私钥文件
  28. // key: require('fs').readFileSync(path.resolve(__dirname, './src/ssl/key.pem')),
  29. // // 读取证书文件
  30. // cert: require('fs').readFileSync(path.resolve(__dirname, './src/ssl/cert.pem'))
  31. // },
  32. port: port,
  33. open: true,
  34. overlay: {
  35. warnings: false,
  36. errors: true
  37. },
  38. proxy: {
  39. '/api': {
  40. target: process.env.VUE_APP_BASE_API,
  41. changeOrigin: true,
  42. pathRewrite: {
  43. '^/api': 'api'
  44. }
  45. },
  46. '/auth': {
  47. target: process.env.VUE_APP_BASE_API,
  48. changeOrigin: true,
  49. pathRewrite: {
  50. '^/auth': 'auth'
  51. }
  52. },
  53. '/fengmap': {
  54. target: 'https://developer.fengmap.com/',
  55. changeOrigin: true,
  56. pathRewrite: { '^/fengmap': '' }
  57. }
  58. }
  59. },
  60. configureWebpack: {
  61. name: name,
  62. resolve: {
  63. alias: {
  64. '@': resolve('src'),
  65. '@crud': resolve('src/components/Crud')
  66. }
  67. },
  68. performance: {
  69. hints: 'warning',
  70. // 入口起点的最大体积
  71. maxEntrypointSize: 50000000,
  72. // 生成文件的最大体积
  73. maxAssetSize: 30000000
  74. }
  75. // plugins: [
  76. // new GenerateAssetPlugin({
  77. // filename: 'server-config.json',
  78. // fn: (compilation, cb) => {
  79. // cb(null, createServerConfig(compilation))
  80. // },
  81. // extraFiles: []
  82. // })
  83. // ]
  84. },
  85. chainWebpack(config) {
  86. config.plugins.delete('preload') // TODO: need test
  87. config.plugins.delete('prefetch') // TODO: need test
  88. // set svg-sprite-loader
  89. config.module
  90. .rule('svg')
  91. .exclude.add(resolve('src/assets/icons'))
  92. .end()
  93. config.module
  94. .rule('icons')
  95. .test(/\.svg$/)
  96. .include.add(resolve('src/assets/icons'))
  97. .end()
  98. .use('svg-sprite-loader')
  99. .loader('svg-sprite-loader')
  100. .options({
  101. symbolId: 'icon-[name]'
  102. })
  103. .end()
  104. // set preserveWhitespace
  105. config.module
  106. .rule('vue')
  107. .use('vue-loader')
  108. .loader('vue-loader')
  109. .tap(options => {
  110. options.compilerOptions.preserveWhitespace = true
  111. return options
  112. })
  113. .end()
  114. config
  115. // https://webpack.js.org/configuration/devtool/#development
  116. .when(process.env.NODE_ENV === 'development',
  117. config => config.devtool('cheap-source-map')
  118. )
  119. config
  120. .when(process.env.NODE_ENV !== 'development',
  121. config => {
  122. config
  123. .plugin('ScriptExtHtmlWebpackPlugin')
  124. .after('html')
  125. .use('script-ext-html-webpack-plugin', [{
  126. // `runtime` must same as runtimeChunk name. default is `runtime`
  127. inline: /runtime\..*\.js$/
  128. }])
  129. .end()
  130. config
  131. .optimization.splitChunks({
  132. chunks: 'all',
  133. cacheGroups: {
  134. libs: {
  135. name: 'chunk-libs',
  136. test: /[\\/]node_modules[\\/]/,
  137. priority: 10,
  138. chunks: 'initial' // only package third parties that are initially dependent
  139. },
  140. elementUI: {
  141. name: 'chunk-elementUI', // split elementUI into a single package
  142. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  143. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  144. },
  145. commons: {
  146. name: 'chunk-commons',
  147. test: resolve('src/components'), // can customize your rules
  148. minChunks: 3, // minimum common number
  149. priority: 5,
  150. reuseExistingChunk: true
  151. }
  152. }
  153. })
  154. config.optimization.runtimeChunk('single')
  155. }
  156. )
  157. },
  158. transpileDependencies: [
  159. 'vue-echarts',
  160. 'resize-detector'
  161. ]
  162. }