vue.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const { defineConfig } = require('@vue/cli-service')
  2. const path = require('path')
  3. const webpack = require('webpack')
  4. const CopyWebpackPlugin = require('copy-webpack-plugin')
  5. const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
  6. module.exports = defineConfig({
  7. transpileDependencies: true,
  8. publicPath: '/sddnWeihe',
  9. assetsDir: 'static',
  10. outputDir: 'dist',
  11. lintOnSave: false, // 是否开启eslint
  12. productionSourceMap: false, // 生产环境是否生成sourceMap
  13. filenameHashing: true, // 文件名哈希
  14. configureWebpack: (config) => {
  15. if (process.env.VUE_APP_MARS3D_SOURCE === 'module') {
  16. const cesiumSourcePath = 'node_modules/mars3d-cesium/Build/Cesium/' // cesium库安装目录
  17. const cesiumRunPath = './mars3d-cesium/' // cesium运行时路径
  18. let plugins = [
  19. // 标识cesium资源所在的主目录,cesium内部资源加载、多线程等处理时需要用到
  20. new webpack.DefinePlugin({
  21. CESIUM_BASE_URL: JSON.stringify(path.join(config.output.publicPath, cesiumRunPath))
  22. }),
  23. // Cesium相关资源目录需要拷贝到系统目录下面(部分CopyWebpackPlugin版本的语法可能没有patterns)
  24. new CopyWebpackPlugin({
  25. patterns: [
  26. { from: path.join(cesiumSourcePath, 'Workers'), to: path.join(config.output.path, cesiumRunPath, 'Workers') },
  27. { from: path.join(cesiumSourcePath, 'Assets'), to: path.join(config.output.path, cesiumRunPath, 'Assets') },
  28. { from: path.join(cesiumSourcePath, 'ThirdParty'), to: path.join(config.output.path, cesiumRunPath, 'ThirdParty') },
  29. { from: path.join(cesiumSourcePath, 'Widgets'), to: path.join(config.output.path, cesiumRunPath, 'Widgets') }
  30. ]
  31. }),
  32. new NodePolyfillPlugin()
  33. ]
  34. return {
  35. module: { unknownContextCritical: false }, // 配置加载的模块类型,cesium时必须配置
  36. plugins: plugins
  37. }
  38. } else {
  39. return {
  40. externals: { 'mars3d-cesium': 'Cesium' } //排除使用 mars3d-cesium
  41. }
  42. }
  43. },
  44. devServer: {
  45. client: { overlay: false },
  46. host: '0.0.0.0', // 也可以直接写IP地址这样方便真机测试
  47. port: 3000, // 端口号
  48. open: false, // 配置自动启动浏览器
  49. proxy: {
  50. '/system-biz': {
  51. target: 'http://10.157.225.55:28085',
  52. logLevel: 'debug',
  53. changeOrigin: true,
  54. rewrite: (p) => p.replace(/^\/system-biz/, '')
  55. },
  56. '/api': {
  57. //测试环境
  58. target: 'http://10.157.200.5:28132',//http://192.168.1.185:28131
  59. changOrigin: true
  60. }
  61. }
  62. },
  63. css: {
  64. // 启用 CSS modules
  65. // requireModuleExtension: false,
  66. // 是否使用css分离插件
  67. extract: false,
  68. // 开启 CSS source maps,一般不建议开启
  69. sourceMap: false,
  70. // css预设器配置项
  71. loaderOptions: {
  72. sass: {
  73. additionalData: '@import "mars3d-cesium/Build/Cesium/Widgets/widgets.css"; @import "@/assets/scss/index.scss";'
  74. }
  75. }
  76. }
  77. })