vue.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const CopyWebpackPlugin = require('copy-webpack-plugin')
  2. const webpack = require('webpack')
  3. const cesiumSource = 'node_modules/cesium/Source'
  4. const cesiumWorkers = '../Build/Cesium/Workers'
  5. const path = require("path");
  6. function resolve(dir) {
  7. return path.join(__dirname, dir);
  8. }
  9. module.exports = {
  10. publicPath: './', // 基本路径
  11. outputDir: 'dist', // 构建时的输出目录
  12. assetsDir: 'static', // 放置静态资源的目录
  13. indexPath: 'index.html', // html 的输出路径
  14. filenameHashing: true, // 文件名哈希值
  15. lintOnSave: false, // 是否在保存的时候使用 `eslint-loader` 进行检查。
  16. // 组件是如何被渲染到页面中的? (ast:抽象语法树;vDom:虚拟DOM)
  17. // template ---> ast ---> render ---> vDom ---> 真实的Dom ---> 页面
  18. // runtime-only:将template在打包的时候,就已经编译为render函数
  19. // runtime-compiler:在运行的时候才去编译template
  20. runtimeCompiler: false,
  21. transpileDependencies: [], // babel-loader 默认会跳过 node_modules 依赖。
  22. productionSourceMap: false, // 是否为生产环境构建生成 source map
  23. configureWebpack: {
  24. plugins: [
  25. new CopyWebpackPlugin([{ from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' }]),
  26. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Assets'), to: 'Assets' }]),
  27. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }]),
  28. new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'ThirdParty/Workers'), to: 'ThirdParty/Workers' }]),
  29. new webpack.DefinePlugin({
  30. CESIUM_BASE_URL: JSON.stringify('./')
  31. })
  32. ],
  33. module: {
  34. unknownContextCritical: false,
  35. unknownContextRegExp: /\/cesium\/cesium\/Source\/Core\/buildModuleUrl\.js/
  36. },
  37. // 配置cesium----开始
  38. amd: {
  39. toUrlUndefined: true
  40. },
  41. output: {
  42. sourcePrefix: ' '
  43. }
  44. },
  45. devServer: {
  46. proxy: {
  47. '/socket.io':{
  48. target: 'http://192.168.1.6:1234', // target host
  49. changeOrigin: true, // needed for virtual hosted sites
  50. logLevel: 'debug'
  51. },
  52. '/sockjs-node': {
  53. target: 'http://192.168.1.6:1234',
  54. ws: true,
  55. changeOrigin: true
  56. },
  57. '/api': {
  58. target: 'http://localhost:80',
  59. ws: true,
  60. changeOrigin: true,
  61. // pathRewrite:{
  62. // "^/geoserver":""
  63. // }
  64. }
  65. }
  66. },
  67. chainWebpack: config => {
  68. config.resolve.alias
  69. .set("@", resolve("src"))
  70. .set("assets", resolve("src/assets"))
  71. .set("components", resolve("src/components"))
  72. .set("public", resolve("public"))
  73. .set("cesium", path.resolve(__dirname, cesiumSource))
  74. // set svg-sprite-loader
  75. config.module
  76. .rule('svg')
  77. .exclude.add(resolve('src/assets')) // 存放 svg 目录的目录
  78. .end()
  79. config.module
  80. .rule('assets')
  81. .test(/\.svg$/)
  82. .include.add(resolve('src/assets')) // 存放 svg 目录的目录
  83. .end()
  84. .use('svg-sprite-loader')
  85. .loader('svg-sprite-loader')
  86. .options({
  87. symbolId: 'icon-[name]'
  88. })
  89. .end()
  90. config.module
  91. .rule('glb')
  92. .test(/\.glb$/)
  93. .use('url-loader')
  94. .loader('url-loader')
  95. .end();
  96. }
  97. }