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

165 lines
4.8 KiB

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. }
  54. },
  55. configureWebpack: {
  56. name: name,
  57. resolve: {
  58. alias: {
  59. '@': resolve('src'),
  60. '@crud': resolve('src/components/Crud')
  61. }
  62. },
  63. performance: {
  64. hints: 'warning',
  65. // 入口起点的最大体积
  66. maxEntrypointSize: 50000000,
  67. // 生成文件的最大体积
  68. maxAssetSize: 30000000
  69. }
  70. // plugins: [
  71. // new GenerateAssetPlugin({
  72. // filename: 'server-config.json',
  73. // fn: (compilation, cb) => {
  74. // cb(null, createServerConfig(compilation))
  75. // },
  76. // extraFiles: []
  77. // })
  78. // ]
  79. },
  80. chainWebpack(config) {
  81. config.plugins.delete('preload') // TODO: need test
  82. config.plugins.delete('prefetch') // TODO: need test
  83. // set svg-sprite-loader
  84. config.module
  85. .rule('svg')
  86. .exclude.add(resolve('src/assets/icons'))
  87. .end()
  88. config.module
  89. .rule('icons')
  90. .test(/\.svg$/)
  91. .include.add(resolve('src/assets/icons'))
  92. .end()
  93. .use('svg-sprite-loader')
  94. .loader('svg-sprite-loader')
  95. .options({
  96. symbolId: 'icon-[name]'
  97. })
  98. .end()
  99. // set preserveWhitespace
  100. config.module
  101. .rule('vue')
  102. .use('vue-loader')
  103. .loader('vue-loader')
  104. .tap(options => {
  105. options.compilerOptions.preserveWhitespace = true
  106. return options
  107. })
  108. .end()
  109. config
  110. // https://webpack.js.org/configuration/devtool/#development
  111. .when(process.env.NODE_ENV === 'development',
  112. config => config.devtool('cheap-source-map')
  113. )
  114. config
  115. .when(process.env.NODE_ENV !== 'development',
  116. config => {
  117. config
  118. .plugin('ScriptExtHtmlWebpackPlugin')
  119. .after('html')
  120. .use('script-ext-html-webpack-plugin', [{
  121. // `runtime` must same as runtimeChunk name. default is `runtime`
  122. inline: /runtime\..*\.js$/
  123. }])
  124. .end()
  125. config
  126. .optimization.splitChunks({
  127. chunks: 'all',
  128. cacheGroups: {
  129. libs: {
  130. name: 'chunk-libs',
  131. test: /[\\/]node_modules[\\/]/,
  132. priority: 10,
  133. chunks: 'initial' // only package third parties that are initially dependent
  134. },
  135. elementUI: {
  136. name: 'chunk-elementUI', // split elementUI into a single package
  137. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  138. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  139. },
  140. commons: {
  141. name: 'chunk-commons',
  142. test: resolve('src/components'), // can customize your rules
  143. minChunks: 3, // minimum common number
  144. priority: 5,
  145. reuseExistingChunk: true
  146. }
  147. }
  148. })
  149. config.optimization.runtimeChunk('single')
  150. }
  151. )
  152. },
  153. transpileDependencies: [
  154. 'vue-echarts',
  155. 'resize-detector'
  156. ]
  157. }