安装插件
npm? i??vite-plugin-cesium
配置vite.config.ts
const path = require("path");
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import cesium from 'vite-plugin-cesium'; // 引入插件
// https://vitejs.dev/config/
export default defineConfig({
server: {
open: true,
},
plugins: [vue(), cesium()],
envDir: "./env", //配置env全局变量文件
resolve: {
// 配置路径别名
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});
cesium组件
<template>
<div id="container"></div>
</template>
<script>
import * as Cesium from "cesium";
export default {
name: "HelloCesium",
mounted() {
console.log(Cesium);
const viewer = new Cesium.Viewer("container");
},
};
</script>
<style scoped lang="scss">
#container {
width: 100%;
height: 100%;
}
</style>
|