npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-cesium-build

v0.5.0

Published

CesiumJS support for Vite

Downloads

1,473

Readme

:tada:vite-plugin-cesium-build

English | 简体中文

这会将 Cesium.js 与其样式 widget.css 外部化,并在打包时自动拷贝 CesiumJS 的四大库和核心文件。

它还支持 @cesium/engine !

  • :+1: DX 对开发无影响
  • :sparkles: TypeScript 完全类型支持
  • :rocket: 非常快! 在我的笔记本电脑中,示例项目仅需 300ms 完成打包,这是因为 Cesium 库不参与核心构建。

Alt text

:memo: 使用

如果你 "不关心文档只想尽快让它跑起来", 请移步 examples.

安装此插件

pnpm add -D vite-plugin-cesium-build

vite.config.js中引入

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

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

你已经完成了 CesiumJS 的全部配置!接下来只需要像往常一样开发与打包! 默认情况下,插件会自动把下面的代码添加到你的 index.html 中:

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

如果要阻止这个默认行为,见Options中的customCesiumBaseUrl

如果使用的Cesium版本为v1.97及更高,你可以将 css 选项设置为 true:

export default defineConfig({
  plugins: [
    cesium({ css: true })
  ]
})

这将会自动将Cesium的样式添加到你的 index.html:

<link rel="stylesheet" href="./cesium-package/Widgets/widgets.css">

:wrench: 选项

除此以外,插件提供了一些配置项:

export default defineConfig({
  plugins: [
    cesium({
      /**
       * 这指示了Cesium包文件夹的位置。
       * 这意味着将会从这个文件夹中获取CesiumJS的相关资源。
       */
      from: 'node_modules/cesium/Build/Cesium',

      /**
       * 这指示了构建后资源位置。
       * 这意味着构建后资源会被放在/dist/cesium-package/下
       */
      to: 'cesium-package',

      /**
       * 设置为true时,你需要自行设置CESIUM_BASE_URL。或者输入字符串以直接自定义base url。
       */
      customCesiumBaseUrl: false,
      /**
       * 为 `true` 时, Cesium的样式将会被自动添加.
       */
      css: boolean
    })
  ]
})

完全自定义

他提供了所有内部方法,以支持完全的自定义。在极少数有需要的情况下,请查看对应源码。

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

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

其他

如果你是Vue用户,或许可以尝试一下cesium-use !