vite 和 cesium

CesiumJS是一个开源的JavaScript库,用于在web浏览器中创建3D地球仪和2D地图,而无需插件。它将WebGL用于硬件加速图形,并且是跨平台、跨浏览器的,并针对动态数据可视化进行了调整。来自百度百科

更具cesium的官方教程,你可能需要配置才能正常使用 cesium。

在 vite 的社区插件,我们可以找到 vite-plugin-cesium ,它能够快速搭建 cesium 的开发环境。

npm i vite-plugin-cesium -D

在 vite.config.ts 中添加插件

import { defineConfig } from 'vite';
import cesium from 'vite-plugin-cesium'; // 引入插件
export default defineConfig({
    plugins: [cesium()],
});

centos 安装 nodejs

yum install epel-release

EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentOS和Scientific Linux.

我们在Centos下使用yum安装时往往找不到rpm的情况,官方的rpm repository提供的rpm包也不够丰富,很多时候需要自己编译很痛苦,而EPEL恰恰可以解决这两方面的问题。EPEL的全称叫 Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。

yum install nodejs
yum install npm

linux 归档和压缩

zip 格式并不适linux上使用 ,Windows上的zip包拿到Linux上unzip解压会乱码。

而 tar 格式可以。而 tar 本身不提供压缩,无非就是把包括所有文件的內容和权限拼成一个文件而己,所以用另外如 gzip 格式压缩。为什么是 gzip,因为几乎所有 linux 都支持而已。

如果你的压缩包只在 linux 上用,则使用 tar 没错。

打包文件夹

tar [参数] [打包后的目录或文件(以.tar结尾)] [打包前的目录或源文件]
例:tar -cvf demo.tar demo
参数含义
-c做打包操作,可将多个文件或目录进行打包
-v显示打包过程
-f后接包名(必须要写)指明要打包的目录或源文件的名称

解包

tar [参数] [包名称]
例:tar -xvf abc.tar
解压到指定目录:tar -xvf abc.tar -C test/

参数含义
-x做解打包操作
-v显示解打包过程
-f后接包名(必须要写)指明要解打包的tar包的包名
-t查看tar包中有哪些文件或目录,不做解打包操作
-C(大写)指定解打包的具体位置

打包的同时进行压缩

常用参数及含义如下表所示:

参数含义
-z一步压缩和解压缩 “.tar.gz” 格式
-j一步压缩和解压缩 “.tar.bz2″格式
tar -zcvf demo.tar.gz demo
tar -jcvf abc.tar.bz2 abc
# 注意参数z与j及压缩包的后缀名

tailscale derper

version: "3"
services:
  derper:
    image: fredliang/derper
    container_name: derper
    environment:
      - DERP_DOMAIN=derper.tencent.codeon.cn
      # manual/letsencrypt
      - DERP_CERT_MODE=manual
      # - DERP_ADDR=:1443
    ports:
      - 3478:3478/udp
      - 1443:443
      # - 80:80
    volumes:
      - ./certs:/app/certs:ro
	"derpMap": {
		// "OmitDefaultRegions": true,
		"Regions": {
			"900": {
				"RegionID":   900,
				"RegionCode": "tencent",
				"RegionName": "tencent-cloud",
				"Nodes": [
					{
						"Name":     "1",
						"RegionID": 900,
						"HostName": "derper.tencent.codeon.cn",
						"DERPPort": 1443,
					},
				],
			},
		},
	},

DERPPort 和 docker compose端口1443保持一致

HostName 和 docker compose 中的DERP_DOMAIN保持一致

将证书放在 ./certs 目录。使用 letsencrypt 申请不到

使用 public 结尾的 crt 证书。 9277225_xxx.xxx.xxx.xx_public.crt

nodejs 版本控制 for windows

可以解决多个项目依赖不同的nodejs版本问题 仓库地址

进入仓库 > Releases > 找到最新的版本 > 下载 nvm-setup.exe > 安装

如果之前安装过nodejs,建议先卸载之后在安装 nvm,全程使用 nvm 管理即可。

基本命令

# 下载最新版
nvm install latest
# 下载 14 大版本
nvm install 14
# 切换版本
nvm use 14

install 默认从 github 下载,即需要 vpn ,也可以尝试更改镜像使用。

# 阿里云
nvm npm_mirror https://npmmirror.com/mirrors/npm/
nvm node_mirror https://npmmirror.com/mirrors/node/
# 腾讯云
nvm npm_mirror http://mirrors.cloud.tencent.com/npm/
nvm node_mirror http://mirrors.cloud.tencent.com/nodejs-release/

rollup 开发 ts 模块总结

使用 rollup.config.ts 文件作为 rollup 的配置

tsconfig.json
    "module": "esnext",   

    "moduleResolution": "node",  
你需要的开发依赖是
"@rollup/plugin-typescript": "^11.0.0",
"tslib": "^2.4.1",
"typescript": "^4.9.4"
版本为示例版本,建议安装最新的。
output配置

建议同时输出 es 和 cjs 两个格式

# rollup.config.ts
output: [
        {
            file: './dist/bundle.ejs',
            format: 'es',
        },
        {
            file: './dist/bundle.cjs',
            format: 'cjs',
        }
    ]

在 package.json 中配置

  "main": "./dist/bundle.cjs",
  "module": "./dist/bundle.ejs",

这样即可使用 require 导入 ,也可以使用 import 导入。

编译脚本
# package.json
"scripts": {
    "build": "rollup --config rollup.config.ts --configPlugin typescript"
  },

编译类型声明文件

在 rollup.config.ts 的插件中配置如下

plugins: [
        del({targets: 'dist/*'}),
        typescript({
            compilerOptions: {declaration: true, outDir: './dist'},
            include: "src/**/*"
        })
    ],

排除模块

在 rollup.config.ts 的插件中配置如下

// input
// output
// plugins
external: ['axios']

建议依赖格式

"peerDependencies": {
    "axios": "^1.2.2"
  }

使用 jest 测试

需要的依赖:
jest
@types/jest

防止编译test目录,可以这样做

# rollup.config.ts
plugins: [
        del({targets: 'dist/*'}),
        typescript({
            compilerOptions: {declaration: true, outDir: './dist'},
            include: "src/**/*"
        })
    ],

发布 npm 包

如何使用 buddy 的流水线自动发布私有npm包呢?

这里使用的是 buddy 的自主托管版本和 gitlab ce 。 npm 注册表使用的是 gitlab 的软件仓库。

在 buddy 里创建项目,将需要发布的项目代码 clone 下来。

如果是从 gitlab ce 上 clone ,使用 oAuth 方式可能会遇到问题。

本文使用的是个人令牌的方式。

为项目创建流水线,并在 操作 于运行 栏目下,选择添加按钮。然后选中 node.js 项。

之后,在运行栏目下,输入本次的命令

# yarn install
# 安装依赖
npm ci
# 配置注册表和令牌
npm config --location=project set @zhangtx:registry=https://$GITLAB_HOST/api/v4/projects/$GITLAB_PROJECT_ID/packages/npm/
npm config --location=project set //$GITLAB_HOST/api/v4/projects/$GITLAB_PROJECT_ID/packages/npm/:_authToken=$GITLAB_NPM_PUBLISH_PACKAGE_TOKEN
# 编译
npm run build
# 发布
npm publish

注意其中的 $ 开头的名称,它们是自定义变量。

–location=project 表示修改的是本项目的 .npmrc

@zhangtx 表示范围包。

GITLAB_HOST 是本次 gitlab ce 的域名,你也可以使用ip

GITLAB_PROJECT_ID 时本次项目在 gitlab ce 中的 项目ID。不是项目名称

GITLAB_NPM_PUBLISH_PACKAGE_TOKEN 是发布包时需要的令牌,可以从 gitlab ce的的 个人令牌中获取,注意范围要勾选api

接下来你可以尝试运行这个流水线。

制作基于 mysql 的镜像

直接通过 commit 提交包含数据的MySQL镜像是无效的.

因为 mysql 的镜像使用了卷,而commit不会提交这些数据。

解决方案:

或许可以通过推荐方法来完成这个这件事情

创建一个 Dockerfile 文件。

# @see https://hub.docker.com/_/mysql
FROM mysql:8.0.28

# 创建数据库后按照此文件里面的配置进行初始化,文件将按字母顺序执行
COPY ./docker-entrypoint-initdb.d /docker-entrypoint-initdb.d

# 初始化一个数据库
ENV MYSQL_DATABASE=myDatabase

# 设置root账户密码
ENV MYSQL_ROOT_PASSWORD=123456

myDatabase 是你的数据库名称

123456 是你的 root 账户密码

紧接着,在 ./docker-entrypoint-initdb.d 目录里,放入你你用来初始化数据库的文件,比如 .sql 文件。

摘抄官网原文:When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.

译文:当容器第一次启动时,将创建一个具有指定名称的新数据库,并使用提供的配置变量进行初始化。此外,它将执行在/docker-entrypoint-initdb.d中找到的扩展名为.sh、.sql和.sql.gz的文件。文件将按字母顺序执行。您可以通过将SQL转储挂载到该目录中,并使用贡献的数据提供自定义映像来轻松填充mysql服务。默认情况下,SQL文件将被导入到由MYSQL_DATABASE变量指定的数据库中。

参考网站:mysql – Official Image | Docker Hub