vue.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const CopyWebpackPlugin = require('copy-webpack-plugin')
  4. const cesiumSource = 'node_modules/cesium/Build/Cesium'
  5. module.exports = {
  6. publicPath: './',
  7. assetsDir: './static',
  8. productionSourceMap: false,
  9. lintOnSave: false, // 是否开启eslint
  10. devServer: {
  11. open: true,
  12. port: 8091,
  13. overlay: {
  14. warnings: false,
  15. errors: true,
  16. },
  17. proxy: {
  18. '/yapi': {
  19. target: 'http://192.168.18.200:18082/prod-api/', // 托克托现场
  20. // target: 'https://10.0.0.201:8080/prod-api/', // 托克托现场
  21. // target: 'http://172.168.0.62:8080/prod-api/', // 托克托现场
  22. // target: 'http://192.168.195.136:8080/prod-api/', // 托克托本地虚拟机
  23. // target: "http://localhost:5002", // 远程服务器-赵哥
  24. changeOrigin: true,
  25. pathRewrite: {
  26. '^/yapi': '/',
  27. },
  28. },
  29. '/model': {
  30. // target: 'https://10.0.0.201:8081/model/', //托克托模型现场服务器
  31. // target: 'http://172.168.0.62:8081/model/', //托克托模型现场服务器
  32. target: 'http://192.168.195.136:8081/model/', //托克托模型虚拟机
  33. changeOrigin: true,
  34. pathRewrite: {
  35. '^/model': '/',
  36. },
  37. },
  38. },
  39. },
  40. configureWebpack: config => {
  41. let plugins = []
  42. if (process.env.NODE_ENV === 'production') {
  43. plugins = [
  44. new webpack.DefinePlugin({
  45. CESIUM_BASE_URL: JSON.stringify('static'),
  46. }),
  47. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Workers'), to: 'static/Workers' }]),
  48. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Assets'), to: 'static/Assets' }]),
  49. new CopyWebpackPlugin([
  50. {
  51. from: path.join(cesiumSource, 'ThirdParty'),
  52. to: 'static/ThirdParty',
  53. },
  54. ]),
  55. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Widgets'), to: 'static/Widgets' }]),
  56. new webpack.ProvidePlugin({
  57. process: 'process/browser',
  58. Buffer: ['buffer', 'Buffer'],
  59. }),
  60. ]
  61. } else {
  62. plugins = [
  63. new webpack.DefinePlugin({
  64. CESIUM_BASE_URL: JSON.stringify(''),
  65. }),
  66. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Workers'), to: 'Workers' }]),
  67. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Assets'), to: 'Assets' }]),
  68. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'ThirdParty'), to: 'ThirdParty' }]),
  69. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }]),
  70. new webpack.ProvidePlugin({
  71. process: 'process/browser',
  72. Buffer: ['buffer', 'Buffer'],
  73. }),
  74. ]
  75. }
  76. return {
  77. module: {
  78. unknownContextCritical: false,
  79. rules: [
  80. {
  81. test: /\.js$/,
  82. enforce: 'pre',
  83. include: path.resolve(__dirname, 'node_modules/cesium/Source'),
  84. sideEffects: false,
  85. use: [
  86. {
  87. loader: 'strip-pragma-loader',
  88. options: {
  89. pragmas: {
  90. debug: false,
  91. },
  92. },
  93. },
  94. ],
  95. },
  96. {
  97. test: /.js$/,
  98. include: path.resolve(__dirname, 'node_modules/cesium/Source'),
  99. use: {
  100. loader: require.resolve('@open-wc/webpack-import-meta-loader'),
  101. },
  102. },
  103. ],
  104. },
  105. optimization: {
  106. usedExports: true,
  107. splitChunks: {
  108. maxInitialRequests: Infinity,
  109. minSize: 0,
  110. maxSize: 250000,
  111. cacheGroups: {
  112. vendor: {
  113. test: /[\\/]node_modules[\\/]/,
  114. priority: -10,
  115. chunks: 'all',
  116. name(module) {
  117. const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
  118. return `npm.${packageName.replace('@', '')}`
  119. },
  120. },
  121. commons: {
  122. name: 'Cesium',
  123. test: /[\\/]node_modules[\\/]cesium/,
  124. priority: 10,
  125. chunks: 'all',
  126. },
  127. },
  128. },
  129. },
  130. output: {
  131. sourcePrefix: ' ',
  132. },
  133. amd: {
  134. toUrlUndefined: true,
  135. },
  136. resolve: {
  137. alias: {
  138. '@': path.resolve('src'),
  139. },
  140. },
  141. node: {
  142. fs: 'empty',
  143. Buffer: false,
  144. http: 'empty',
  145. https: 'empty',
  146. zlib: 'empty',
  147. },
  148. plugins: plugins,
  149. }
  150. },
  151. }