Skip to content

s3xysteak/vite-plugin-cesium-build

Repository files navigation

🎉vite-plugin-cesium-build

English | 简体中文

It externalizes Cesium.js and automatically copies the four major libraries and core files of CesiumJS during the build process.

It also support @cesium/engine !

  • 👍 DX Zero impact on development
  • TypeScript Type support.
  • 🚀 Super fast! In my laptop, the sample project only takes 300ms to complete the build because the Cesium library is not involved in the core build.

Alt text

📝 Usage

Install this plugin

pnpm add -D vite-plugin-cesium-build

Import it in vite.config.js

import { defineConfig } from 'vite'
import cesium from 'vite-plugin-cesium-build'
// import cesium from 'vite-plugin-cesium-build/engine'

export default defineConfig({
  plugins: [
    //...
    cesium()
  ]
})

You have completed the entire configuration for CesiumJS! Now you can continue development and build as usual! By default, This plugin will automatically add the code to your index.html:

// Customize variable 'to' in options
Object.defineProperty(globalThis, 'CESIUM_BASE_URL', {
  value: '/${to}/'
})

To prevent it, see customCesiumBaseUrl in Options.

🔧 Options

In addition, the plugin provides some configuration options:

export default defineConfig({
  plugins: [
    cesium({
      /**
       * Specifies the location of the Cesium package folder
       * Which means the relevant resources of CesiumJS will be obtained from this folder
       */
      from: 'node_modules/cesium/Build/Cesium',

      /**
       * Specifies the location of the built resources
       * Which means the built resources will be placed under /dist/cesium-package/
       */
      to: 'cesium-package',

      /**
       * If `true`, you need to manually set the CESIUM_BASE_URL.
       */
      customCesiumBaseUrl: false
    })
  ]
})

Fully customizable

It also provide some internal methods to support fully customizable. In the rare case that it is necessary, please check the corresponding source code.

import { defineConfig } from 'vite'
import { copyCesium, importCesium, setBaseUrl } from 'vite-plugin-cesium-build/core'

export default defineConfig({
  plugins: [
    [
      copyCesium(
        // ...
      ),
      importCesium(
        // ...
      ),
      setBaseUrl(
        // ...
      )
    ]
  ]
})

Others

If you are a Vue user, maybe try cesium-use !

About

A devDependencies used to automatically configure CesiumJS for development and build with Vite.

Resources

License

Stars

Watchers

Forks

Packages

No packages published