vue.config.js 4.5 KB

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