feat: 1.2.3版本发布
This commit is contained in:
parent
2ec92f0020
commit
446c843f8f
66
README.md
66
README.md
|
@ -1,6 +1,6 @@
|
|||
# ⚡ vite-plugin-earth
|
||||
|
||||
Easily set up a [`Cesium`] & [`mars3d`] project in [`Vite`].
|
||||
Easily set up a [`cesium`] & [`mars3d-cesium`] project in [`Vite`].
|
||||
|
||||
[`cesium`]: https://github.com/CesiumGS/cesium
|
||||
[`mars3d`]: https://mars3d.cn/
|
||||
|
@ -8,8 +8,7 @@ Easily set up a [`Cesium`] & [`mars3d`] project in [`Vite`].
|
|||
## Install
|
||||
|
||||
```bash
|
||||
npm i cesium vite-plugin-earth vite -D
|
||||
# yarn add cesium vite-plugin-earth vite -D
|
||||
npm i vite-plugin-earth -D
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
@ -18,28 +17,53 @@ add this plugin to `vite.config.js`
|
|||
|
||||
```js
|
||||
import { defineConfig } from 'vite';
|
||||
import earthPlugin from 'vite-plugin-earth';
|
||||
import earth from 'vite-plugin-earth';
|
||||
export default defineConfig({
|
||||
plugins: [earthPlugin()]
|
||||
plugins: [earth()]
|
||||
});
|
||||
```
|
||||
|
||||
add dev command to `package.json`
|
||||
|
||||
```json
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
}
|
||||
```
|
||||
|
||||
run:
|
||||
|
||||
`yarn dev`
|
||||
|
||||
## Options
|
||||
|
||||
**rebuildCesium**
|
||||
### **pkgName**
|
||||
|
||||
- **Type :** `string`
|
||||
- **Default :** `cesium`
|
||||
|
||||
`mars3d-cesium` 为`mars3d`对应的依赖库
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'vite';
|
||||
import earth from 'vite-plugin-earth';
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
earth({
|
||||
pkgName: 'mars3d-cesium'
|
||||
})
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
### **libPath**
|
||||
|
||||
- **Type :** `string`
|
||||
- **Default :** `lib`
|
||||
|
||||
将类库复制到指定的`lib/`目录下面
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'vite';
|
||||
import earth from 'vite-plugin-earth';
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
earth({
|
||||
libPath: 'lib'
|
||||
})
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
### **rebuildCesium**
|
||||
|
||||
- **Type :** `boolean`
|
||||
- **Default :** `false`
|
||||
|
@ -48,10 +72,10 @@ Default copy min cesium file to dist. if `true` will rebuild cesium from source.
|
|||
|
||||
```js
|
||||
import { defineConfig } from 'vite';
|
||||
import earthPlugin from 'vite-plugin-earth';
|
||||
import earth from 'vite-plugin-earth';
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
earthPlugin({
|
||||
earth({
|
||||
rebuildCesium: true
|
||||
})
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "vite-plugin-earth",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.3",
|
||||
"description": "cesium & mars3d library plugin for Vite",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
68
src/index.ts
68
src/index.ts
|
@ -7,30 +7,28 @@ import fs from 'fs-extra';
|
|||
import serveStatic from 'serve-static';
|
||||
import { HtmlTagDescriptor, normalizePath, Plugin } from 'vite';
|
||||
|
||||
interface VitePluginCesiumOptions {
|
||||
libsPath?: String;
|
||||
useUnminified?: Boolean;
|
||||
npmPkgName?: String;
|
||||
useMars3d?: Boolean;
|
||||
interface PluginOptions {
|
||||
libPath: String;
|
||||
useUnminified: Boolean;
|
||||
pkgName: 'mars3d-cesium' | 'cesium';
|
||||
}
|
||||
|
||||
function vitePluginCesium(
|
||||
options: VitePluginCesiumOptions = {
|
||||
libsPath: 'libs',
|
||||
function vitePluginEarth(
|
||||
options: PluginOptions = {
|
||||
libPath: 'lib',
|
||||
useUnminified: false,
|
||||
npmPkgName: 'mars3d-cesium',
|
||||
useMars3d: false
|
||||
pkgName: 'cesium'
|
||||
}
|
||||
): Plugin {
|
||||
const cesiumBuildPath = `./node_modules/${options.npmPkgName}/Build`;
|
||||
const cesiumBuildPath = `./node_modules/${options.pkgName}/Build`;
|
||||
let base = '/';
|
||||
let outDir = 'dist';
|
||||
let isBuild = false;
|
||||
let libsPath = options.libsPath || 'libs';
|
||||
let libPath = options.libPath || 'lib';
|
||||
let useUnminified = options.useUnminified || false;
|
||||
|
||||
return {
|
||||
name: 'vite-plugin-cesium',
|
||||
name: 'vite-plugin-earth',
|
||||
config(config, { command }) {
|
||||
isBuild = command === 'build';
|
||||
base = config.base || '/';
|
||||
|
@ -38,7 +36,7 @@ function vitePluginCesium(
|
|||
},
|
||||
configureServer({ middlewares }) {
|
||||
middlewares.use(
|
||||
`/${libsPath}/Cesium`,
|
||||
`/${libPath}/Cesium`,
|
||||
serveStatic(
|
||||
normalizePath(
|
||||
path.join(
|
||||
|
@ -53,24 +51,8 @@ function vitePluginCesium(
|
|||
if (isBuild) {
|
||||
try {
|
||||
fs.copySync(
|
||||
path.join(cesiumBuildPath, 'Cesium', 'Assets'),
|
||||
path.join(outDir, String(libsPath), 'Cesium', 'Assets')
|
||||
);
|
||||
fs.copySync(
|
||||
path.join(cesiumBuildPath, 'Cesium', 'ThirdParty'),
|
||||
path.join(outDir, String(libsPath), 'Cesium', 'ThirdParty')
|
||||
);
|
||||
fs.copySync(
|
||||
path.join(cesiumBuildPath, 'Cesium', 'Widgets'),
|
||||
path.join(outDir, String(libsPath), 'Cesium', 'Widgets')
|
||||
);
|
||||
fs.copySync(
|
||||
path.join(cesiumBuildPath, 'Cesium', 'Workers'),
|
||||
path.join(outDir, String(libsPath), 'Cesium', 'Workers')
|
||||
);
|
||||
fs.copySync(
|
||||
path.join(cesiumBuildPath, 'Cesium', 'Cesium.js'),
|
||||
path.join(outDir, String(libsPath), 'Cesium', 'Cesium.js')
|
||||
path.join(cesiumBuildPath, 'Cesium'),
|
||||
path.join(outDir, String(libPath), 'Cesium')
|
||||
);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
@ -78,22 +60,22 @@ function vitePluginCesium(
|
|||
|
||||
transformIndexHtml() {
|
||||
let tags: HtmlTagDescriptor[] = [];
|
||||
tags.push({
|
||||
tag: 'script',
|
||||
attrs: {
|
||||
src: normalizePath(
|
||||
path.join(base, String(libsPath), 'Cesium', 'Cesium.js')
|
||||
)
|
||||
},
|
||||
injectTo: 'head'
|
||||
});
|
||||
|
||||
tags.push({
|
||||
tag: 'link',
|
||||
attrs: {
|
||||
rel: 'stylesheet',
|
||||
href: normalizePath(
|
||||
path.join(base, String(libsPath), 'Cesium', 'Widgets/widgets.css')
|
||||
path.join(base, String(libPath), 'Cesium/Widgets/widgets.css')
|
||||
)
|
||||
},
|
||||
injectTo: 'head'
|
||||
});
|
||||
tags.push({
|
||||
tag: 'script',
|
||||
attrs: {
|
||||
src: normalizePath(
|
||||
path.join(base, String(libPath), 'Cesium/Cesium.js')
|
||||
)
|
||||
},
|
||||
injectTo: 'head'
|
||||
|
@ -104,4 +86,4 @@ function vitePluginCesium(
|
|||
};
|
||||
}
|
||||
|
||||
export default vitePluginCesium;
|
||||
export default vitePluginEarth;
|
||||
|
|
Loading…
Reference in New Issue