vue.config.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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: false,
  55. changeOrigin: true
  56. }
  57. }
  58. },
  59. chainWebpack: config => {
  60. config.resolve.alias
  61. .set("@", resolve("src"))
  62. .set("assets", resolve("src/assets"))
  63. .set("components", resolve("src/components"))
  64. .set("public", resolve("public"))
  65. .set("cesium",path.resolve(__dirname, cesiumSource))
  66. // set svg-sprite-loader
  67. config.module
  68. .rule('svg')
  69. .exclude.add(resolve('src/assets')) // 存放 svg 目录的目录
  70. .end()
  71. config.module
  72. .rule('assets')
  73. .test(/\.svg$/)
  74. .include.add(resolve('src/assets')) // 存放 svg 目录的目录
  75. .end()
  76. .use('svg-sprite-loader')
  77. .loader('svg-sprite-loader')
  78. .options({
  79. symbolId: 'icon-[name]'
  80. })
  81. .end()
  82. }
  83. }