无线电资产管理
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.

160 lines
4.6 KiB

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