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