vue.config.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. '/api': {
  42. target: 'http://localhost:80',
  43. ws: true,
  44. changeOrigin: true,
  45. // pathRewrite:{
  46. // "^/geoserver":""
  47. // }
  48. }
  49. },
  50. chainWebpack: config => {
  51. config.resolve.alias
  52. .set("@", resolve("src"))
  53. .set("assets", resolve("src/assets"))
  54. .set("components", resolve("src/components"))
  55. .set("public", resolve("public"))
  56. .set("cesium", path.resolve(__dirname, cesiumSource))
  57. // set svg-sprite-loader
  58. config.module
  59. .rule('svg')
  60. .exclude.add(resolve('src/assets')) // 存放 svg 目录的目录
  61. .end()
  62. config.module
  63. .rule('assets')
  64. .test(/\.svg$/)
  65. .include.add(resolve('src/assets')) // 存放 svg 目录的目录
  66. .end()
  67. .use('svg-sprite-loader')
  68. .loader('svg-sprite-loader')
  69. .options({
  70. symbolId: 'icon-[name]'
  71. })
  72. .end()
  73. config.module
  74. .rule('glb')
  75. .test(/\.glb$/)
  76. .use('url-loader')
  77. .loader('url-loader')
  78. .end();
  79. }
  80. }