vue.config.js 3.3 KB

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