Vue Cli 4 引入 Cesium 配置

一个简单的 Vue Cli 4 引入 Cesium 的架子,可以直接拉取项目,自己扩展。欢迎试用,可以 Star 哟!

原文地址:Vue Cli 4 引入 Cesium 配置

Github: https://github.com/martinageradams/vue-cesium-example

Vue 项目搭建,我就不展示了。按照官网直接一步一步进行就可以。也不展示 webpack 配置的坑了,按照下面的代码配置,项目就能用。

vue.config.js

const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");

module.exports = {
  configureWebpack: {
    plugins: [
      // Copy Cesium Assets, Widgets, and Workers to a static directory
      new CopyWebpackPlugin({
        patterns: [
          { from: "node_modules/cesium/Build/Cesium/Workers", to: "Workers" },
          {
            from: "node_modules/cesium/Build/Cesium/ThirdParty",
            to: "ThirdParty"
          },
          { from: "node_modules/cesium/Build/Cesium/Assets", to: "Assets" },
          { from: "node_modules/cesium/Build/Cesium/Widgets", to: "Widgets" }
        ]
      }),
      new webpack.DefinePlugin({
        // Define relative base path in cesium for loading assets
        CESIUM_BASE_URL: JSON.stringify("")
      })
    ],
    module: {
      // Removes these errors: "Critical dependency: require function is used in a way in which dependencies cannot be statically extracted"
      // https://github.com/AnalyticalGraphicsInc/cesium-webpack-example/issues/6
      unknownContextCritical: false,
      unknownContextRegExp: /\/cesium\/cesium\/Source\/Core\/buildModuleUrl\.js/
    }
  }
};

Map.vue





你可能感兴趣的:(javascript,vue.js,webpack,vue-cli,chrome)