vue.config.js 4.3 KB

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