vue.config.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // 配置加载的模块类型,cesium时必须配置
  36. module: { unknownContextCritical: false },
  37. plugins: plugins
  38. }
  39. } else {
  40. return {
  41. externals: { 'mars3d-cesium': 'Cesium' } //排除使用 mars3d-cesium
  42. }
  43. }
  44. },
  45. devServer: {
  46. client: { overlay: false },
  47. host: '0.0.0.0', // 也可以直接写IP地址这样方便真机测试
  48. port: 3000, // 端口号
  49. open: false, // 配置自动启动浏览器
  50. proxy: {
  51. '/system-biz': {
  52. target: 'http://10.157.225.55:28085',
  53. logLevel: 'debug',
  54. changeOrigin: true,
  55. rewrite: (p) => p.replace(/^\/system-biz/, '')
  56. },
  57. '/api': {
  58. //测试环境
  59. target: 'http://127.0.0.1:28132',//http://192.168.1.185:28131
  60. changOrigin: true,
  61. rewrite: (p) => p.replace(/^\/api/, ''),
  62. }
  63. }
  64. },
  65. css: {
  66. // 启用 CSS modules
  67. // requireModuleExtension: false,
  68. // 是否使用css分离插件
  69. extract: false,
  70. // 开启 CSS source maps,一般不建议开启
  71. sourceMap: false,
  72. // css预设器配置项
  73. loaderOptions: {
  74. sass: {
  75. additionalData: '@import "mars3d-cesium/Build/Cesium/Widgets/widgets.css"; @import "@/assets/scss/index.scss";'
  76. }
  77. }
  78. }
  79. })