commit 474c937d223f04900262ccf2183fceb1ae427db6 Author: xuxb Date: Thu Feb 10 13:08:07 2022 +0800 1.0.8 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8d2ef8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +dist +demo/public +yarn.lock \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b89bc72 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +semi: true +tabWidth: 2 +singleQuote: true +printWidth: 80 +trailingComma: none \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..74bf9ab --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Nshen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd0895c --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# ⚡ vite-plugin-ice-mars3d + +Easily set up a [`Cesium`] project in [`Vite`]. + +[`cesium`]: https://github.com/CesiumGS/cesium +[`mars3d`]: https://mars3d.cn/ + +## Install + +```bash +npm i cesium vite-plugin-ice-mars3d vite -D +# yarn add cesium vite-plugin-ice-mars3d vite -D +``` + +## Usage + +add this plugin to `vite.config.js` + +```js +import { defineConfig } from 'vite'; +import mars3dPlugin from 'vite-plugin-ice-mars3d'; +export default defineConfig({ + plugins: [mars3dPlugin()] +}); +``` + +add dev command to `package.json` + +```json +"scripts": { + "dev": "vite", + "build": "vite build" +} +``` + +run: + +`yarn dev` + +## Options + +**rebuildCesium** + +- **Type :** `boolean` +- **Default :** `false` + +Default copy min cesium file to dist. if `true` will rebuild cesium from source. + +```js +import { defineConfig } from 'vite'; +import mars3dPlugin from 'vite-plugin-ice-mars3d'; +export default defineConfig({ + plugins: [ + mars3dPlugin({ + rebuildCesium: true + }) + ] +}); +``` diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..3aac827 --- /dev/null +++ b/demo/index.html @@ -0,0 +1,14 @@ + + + + + + + cesium-vite + + + + +
+ + diff --git a/demo/package.json b/demo/package.json new file mode 100644 index 0000000..0817f60 --- /dev/null +++ b/demo/package.json @@ -0,0 +1,15 @@ +{ + "name": "cesium-demo", + "version": "1.0.0", + "license": "MIT", + "scripts": { + "dev": "vite", + "build": "vite build", + "serve": "vite build && vite preview" + }, + "devDependencies": { + "cesium": "^1.88.0", + "vite": "^2.7.1", + "vite-plugin-cesium": "^1.2.13" + } +} diff --git a/demo/src/css/main.css b/demo/src/css/main.css new file mode 100644 index 0000000..902b715 --- /dev/null +++ b/demo/src/css/main.css @@ -0,0 +1,7 @@ +html, body, #cesiumContainer { + width: 100%; + height: 100%; + margin: 0; + padding: 0; + overflow: hidden; +} \ No newline at end of file diff --git a/demo/src/index.js b/demo/src/index.js new file mode 100644 index 0000000..391e1ab --- /dev/null +++ b/demo/src/index.js @@ -0,0 +1,11 @@ +/** + * You can also import Cesium Object like this + * + * import * as Cesium from 'cesium'; + * const viewer = new Cesium.Viewer('cesiumContainer'); + */ + +import { Viewer } from 'cesium'; +import './css/main.css'; + +const viewer = new Viewer('cesiumContainer'); diff --git a/demo/vite.config.js b/demo/vite.config.js new file mode 100644 index 0000000..3a93255 --- /dev/null +++ b/demo/vite.config.js @@ -0,0 +1,5 @@ +import { defineConfig } from 'vite'; +import cesium from 'vite-plugin-cesium'; +export default defineConfig({ + plugins: [cesium()] +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..a971f19 --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "vite-plugin-ice-mars3d", + "version": "1.0.9", + "description": "mars3d library plugin for Vite", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "dev": "tsc -w" + }, + "keywords": [ + "vite", + "vite-plugin", + "cesium", + "mars3d" + ], + "author": "xuwoool@qq.com", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+http://git.hfxtsk.cn" + }, + "bugs": { + "url": "http://git.hfxtsk.cn" + }, + "dependencies": { + "fs-extra": "^9.1.0", + "rollup-plugin-external-globals": "^0.6.1", + "serve-static": "^1.14.1" + }, + "devDependencies": { + "@tsconfig/node12": "^1.0.7", + "@types/fs-extra": "^9.0.8", + "@types/node": "^14.14.31", + "@types/serve-static": "^1.13.9", + "prettier": "^2.2.1", + "typescript": "^4.2.2", + "vite": "^2.7.1" + }, + "peerDependencies": { + "mars3d-cesium": "^1.88.0" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..2538dab --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,570 @@ +lockfileVersion: 5.3 + +specifiers: + '@tsconfig/node12': ^1.0.7 + '@types/fs-extra': ^9.0.8 + '@types/node': ^14.14.31 + '@types/serve-static': ^1.13.9 + fs-extra: ^9.1.0 + prettier: ^2.2.1 + rollup-plugin-external-globals: ^0.6.1 + serve-static: ^1.14.1 + typescript: ^4.2.2 + vite: ^2.7.1 + +dependencies: + fs-extra: 9.1.0 + rollup-plugin-external-globals: 0.6.1 + serve-static: 1.14.2 + +devDependencies: + '@tsconfig/node12': 1.0.9 + '@types/fs-extra': 9.0.13 + '@types/node': 14.18.10 + '@types/serve-static': 1.13.10 + prettier: 2.5.1 + typescript: 4.5.5 + vite: 2.8.0 + +packages: + + /@rollup/pluginutils/4.1.2: + resolution: {integrity: sha512-ROn4qvkxP9SyPeHaf7uQC/GPFY6L/OWy9+bd9AwcjOAWQwxRscoEyAUD8qCY5o5iL4jqQwoLk2kaTKJPb/HwzQ==} + engines: {node: '>= 8.0.0'} + dependencies: + estree-walker: 2.0.2 + picomatch: 2.3.1 + dev: false + + /@tsconfig/node12/1.0.9: + resolution: {integrity: sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==} + dev: true + + /@types/estree/0.0.51: + resolution: {integrity: sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==} + dev: false + + /@types/fs-extra/9.0.13: + resolution: {integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==} + dependencies: + '@types/node': 14.18.10 + dev: true + + /@types/mime/1.3.2: + resolution: {integrity: sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==} + dev: true + + /@types/node/14.18.10: + resolution: {integrity: sha512-6iihJ/Pp5fsFJ/aEDGyvT4pHGmCpq7ToQ/yf4bl5SbVAvwpspYJ+v3jO7n8UyjhQVHTy+KNszOozDdv+O6sovQ==} + dev: true + + /@types/serve-static/1.13.10: + resolution: {integrity: sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ==} + dependencies: + '@types/mime': 1.3.2 + '@types/node': 14.18.10 + dev: true + + /at-least-node/1.0.0: + resolution: {integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==} + engines: {node: '>= 4.0.0'} + dev: false + + /debug/2.6.9: + resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} + dependencies: + ms: 2.0.0 + dev: false + + /depd/1.1.2: + resolution: {integrity: sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=} + engines: {node: '>= 0.6'} + dev: false + + /destroy/1.0.4: + resolution: {integrity: sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=} + dev: false + + /ee-first/1.1.1: + resolution: {integrity: sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=} + dev: false + + /encodeurl/1.0.2: + resolution: {integrity: sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=} + engines: {node: '>= 0.8'} + dev: false + + /esbuild-android-arm64/0.14.21: + resolution: {integrity: sha512-Bqgld1TY0wZv8TqiQmVxQFgYzz8ZmyzT7clXBDZFkOOdRybzsnj8AZuK1pwcLVA7Ya6XncHgJqIao7NFd3s0RQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-64/0.14.21: + resolution: {integrity: sha512-j+Eg+e13djzyYINVvAbOo2/zvZ2DivuJJTaBrJnJHSD7kUNuGHRkHoSfFjbI80KHkn091w350wdmXDNSgRjfYQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-arm64/0.14.21: + resolution: {integrity: sha512-nDNTKWDPI0RuoPj5BhcSB2z5EmZJJAyRtZLIjyXSqSpAyoB8eyAKXl4lB8U2P78Fnh4Lh1le/fmpewXE04JhBQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-64/0.14.21: + resolution: {integrity: sha512-zIurkCHXhxELiDZtLGiexi8t8onQc2LtuE+S7457H/pP0g0MLRKMrsn/IN4LDkNe6lvBjuoZZi2OfelOHn831g==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-arm64/0.14.21: + resolution: {integrity: sha512-wdxMmkJfbwcN+q85MpeUEamVZ40FNsBa9mPq8tAszDn8TRT2HoJvVRADPIIBa9SWWwlDChIMjkDKAnS3KS/sPA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-32/0.14.21: + resolution: {integrity: sha512-fmxvyzOPPh2xiEHojpCeIQP6pXcoKsWbz3ryDDIKLOsk4xp3GbpHIEAWP0xTeuhEbendmvBDVKbAVv3PnODXLg==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-64/0.14.21: + resolution: {integrity: sha512-edZyNOv1ql+kpmlzdqzzDjRQYls+tSyi4QFi+PdBhATJFUqHsnNELWA9vMSzAaInPOEaVUTA5Ml28XFChcy4DA==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm/0.14.21: + resolution: {integrity: sha512-aSU5pUueK6afqmLQsbU+QcFBT62L+4G9hHMJDHWfxgid6hzhSmfRH9U/f+ymvxsSTr/HFRU4y7ox8ZyhlVl98w==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm64/0.14.21: + resolution: {integrity: sha512-t5qxRkq4zdQC0zXpzSB2bTtfLgOvR0C6BXYaRE/6/k8/4SrkZcTZBeNu+xGvwCU4b5dU9ST9pwIWkK6T1grS8g==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-mips64le/0.14.21: + resolution: {integrity: sha512-jLZLQGCNlUsmIHtGqNvBs3zN+7a4D9ckf0JZ+jQTwHdZJ1SgV9mAjbB980OFo66LoY+WeM7t3WEnq3FjI1zw4A==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-ppc64le/0.14.21: + resolution: {integrity: sha512-4TWxpK391en2UBUw6GSrukToTDu6lL9vkm3Ll40HrI08WG3qcnJu7bl8e1+GzelDsiw1QmfAY/nNvJ6iaHRpCQ==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-riscv64/0.14.21: + resolution: {integrity: sha512-fElngqOaOfTsF+u+oetDLHsPG74vB2ZaGZUqmGefAJn3a5z9Z2pNa4WpVbbKgHpaAAy5tWM1m1sbGohj6Ki6+Q==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-s390x/0.14.21: + resolution: {integrity: sha512-brleZ6R5fYv0qQ7ZBwenQmP6i9TdvJCB092c/3D3pTLQHBGHJb5zWgKxOeS7bdHzmLy6a6W7GbFk6QKpjyD6QA==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-netbsd-64/0.14.21: + resolution: {integrity: sha512-nCEgsLCQ8RoFWVV8pVI+kX66ICwbPP/M9vEa0NJGIEB/Vs5sVGMqkf67oln90XNSkbc0bPBDuo4G6FxlF7PN8g==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-openbsd-64/0.14.21: + resolution: {integrity: sha512-h9zLMyVD0T73MDTVYIb/qUTokwI6EJH9O6wESuTNq6+XpMSr6C5aYZ4fvFKdNELW+Xsod+yDS2hV2JTUAbFrLA==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-sunos-64/0.14.21: + resolution: {integrity: sha512-Kl+7Cot32qd9oqpLdB1tEGXEkjBlijrIxMJ0+vlDFaqsODutif25on0IZlFxEBtL2Gosd4p5WCV1U7UskNQfXA==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-32/0.14.21: + resolution: {integrity: sha512-V7vnTq67xPBUCk/9UtlolmQ798Ecjdr1ZoI1vcSgw7M82aSSt0eZdP6bh5KAFZU8pxDcx3qoHyWQfHYr11f22A==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-64/0.14.21: + resolution: {integrity: sha512-kDgHjKOHwjfJDCyRGELzVxiP/RBJBTA+wyspf78MTTJQkyPuxH2vChReNdWc+dU2S4gIZFHMdP1Qrl/k22ZmaA==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-arm64/0.14.21: + resolution: {integrity: sha512-8Sbo0zpzgwWrwjQYLmHF78f7E2xg5Ve63bjB2ng3V2aManilnnTGaliq2snYg+NOX60+hEvJHRdVnuIAHW0lVw==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild/0.14.21: + resolution: {integrity: sha512-7WEoNMBJdLN993dr9h0CpFHPRc3yFZD+EAVY9lg6syJJ12gc5fHq8d75QRExuhnMkT2DaRiIKFThRvDWP+fO+A==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + esbuild-android-arm64: 0.14.21 + esbuild-darwin-64: 0.14.21 + esbuild-darwin-arm64: 0.14.21 + esbuild-freebsd-64: 0.14.21 + esbuild-freebsd-arm64: 0.14.21 + esbuild-linux-32: 0.14.21 + esbuild-linux-64: 0.14.21 + esbuild-linux-arm: 0.14.21 + esbuild-linux-arm64: 0.14.21 + esbuild-linux-mips64le: 0.14.21 + esbuild-linux-ppc64le: 0.14.21 + esbuild-linux-riscv64: 0.14.21 + esbuild-linux-s390x: 0.14.21 + esbuild-netbsd-64: 0.14.21 + esbuild-openbsd-64: 0.14.21 + esbuild-sunos-64: 0.14.21 + esbuild-windows-32: 0.14.21 + esbuild-windows-64: 0.14.21 + esbuild-windows-arm64: 0.14.21 + dev: true + + /escape-html/1.0.3: + resolution: {integrity: sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=} + dev: false + + /estree-walker/2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + dev: false + + /etag/1.8.1: + resolution: {integrity: sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=} + engines: {node: '>= 0.6'} + dev: false + + /fresh/0.5.2: + resolution: {integrity: sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=} + engines: {node: '>= 0.6'} + dev: false + + /fs-extra/9.1.0: + resolution: {integrity: sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==} + engines: {node: '>=10'} + dependencies: + at-least-node: 1.0.0 + graceful-fs: 4.2.9 + jsonfile: 6.1.0 + universalify: 2.0.0 + dev: false + + /fsevents/2.3.2: + resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /function-bind/1.1.1: + resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} + dev: true + + /graceful-fs/4.2.9: + resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==} + dev: false + + /has/1.0.3: + resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==} + engines: {node: '>= 0.4.0'} + dependencies: + function-bind: 1.1.1 + dev: true + + /http-errors/1.8.1: + resolution: {integrity: sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==} + engines: {node: '>= 0.6'} + dependencies: + depd: 1.1.2 + inherits: 2.0.4 + setprototypeof: 1.2.0 + statuses: 1.5.0 + toidentifier: 1.0.1 + dev: false + + /inherits/2.0.4: + resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + dev: false + + /is-core-module/2.8.1: + resolution: {integrity: sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==} + dependencies: + has: 1.0.3 + dev: true + + /is-reference/1.2.1: + resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==} + dependencies: + '@types/estree': 0.0.51 + dev: false + + /jsonfile/6.1.0: + resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} + dependencies: + universalify: 2.0.0 + optionalDependencies: + graceful-fs: 4.2.9 + dev: false + + /magic-string/0.25.7: + resolution: {integrity: sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==} + dependencies: + sourcemap-codec: 1.4.8 + dev: false + + /mime/1.6.0: + resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==} + engines: {node: '>=4'} + hasBin: true + dev: false + + /ms/2.0.0: + resolution: {integrity: sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=} + dev: false + + /ms/2.1.3: + resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + dev: false + + /nanoid/3.2.0: + resolution: {integrity: sha512-fmsZYa9lpn69Ad5eDn7FMcnnSR+8R34W9qJEijxYhTbfOWzr22n1QxCMzXLK+ODyW2973V3Fux959iQoUxzUIA==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + dev: true + + /on-finished/2.3.0: + resolution: {integrity: sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=} + engines: {node: '>= 0.8'} + dependencies: + ee-first: 1.1.1 + dev: false + + /parseurl/1.3.3: + resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==} + engines: {node: '>= 0.8'} + dev: false + + /path-parse/1.0.7: + resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} + dev: true + + /picocolors/1.0.0: + resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} + dev: true + + /picomatch/2.3.1: + resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} + engines: {node: '>=8.6'} + dev: false + + /postcss/8.4.6: + resolution: {integrity: sha512-OovjwIzs9Te46vlEx7+uXB0PLijpwjXGKXjVGGPIGubGpq7uh5Xgf6D6FiJ/SzJMBosHDp6a2hiXOS97iBXcaA==} + engines: {node: ^10 || ^12 || >=14} + dependencies: + nanoid: 3.2.0 + picocolors: 1.0.0 + source-map-js: 1.0.2 + dev: true + + /prettier/2.5.1: + resolution: {integrity: sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==} + engines: {node: '>=10.13.0'} + hasBin: true + dev: true + + /range-parser/1.2.1: + resolution: {integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==} + engines: {node: '>= 0.6'} + dev: false + + /resolve/1.22.0: + resolution: {integrity: sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==} + hasBin: true + dependencies: + is-core-module: 2.8.1 + path-parse: 1.0.7 + supports-preserve-symlinks-flag: 1.0.0 + dev: true + + /rollup-plugin-external-globals/0.6.1: + resolution: {integrity: sha512-mlp3KNa5sE4Sp9UUR2rjBrxjG79OyZAh/QC18RHIjM+iYkbBwNXSo8DHRMZWtzJTrH8GxQ+SJvCTN3i14uMXIA==} + peerDependencies: + rollup: ^2.25.0 + dependencies: + '@rollup/pluginutils': 4.1.2 + estree-walker: 2.0.2 + is-reference: 1.2.1 + magic-string: 0.25.7 + dev: false + + /rollup/2.67.1: + resolution: {integrity: sha512-1Sbcs4OuW+aD+hhqpIRl+RqooIpF6uQcfzU/QSI7vGkwADY6cM4iLsBGRM2CGLXDTDN5y/yShohFmnKegSPWzg==} + engines: {node: '>=10.0.0'} + hasBin: true + optionalDependencies: + fsevents: 2.3.2 + dev: true + + /send/0.17.2: + resolution: {integrity: sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==} + engines: {node: '>= 0.8.0'} + dependencies: + debug: 2.6.9 + depd: 1.1.2 + destroy: 1.0.4 + encodeurl: 1.0.2 + escape-html: 1.0.3 + etag: 1.8.1 + fresh: 0.5.2 + http-errors: 1.8.1 + mime: 1.6.0 + ms: 2.1.3 + on-finished: 2.3.0 + range-parser: 1.2.1 + statuses: 1.5.0 + dev: false + + /serve-static/1.14.2: + resolution: {integrity: sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==} + engines: {node: '>= 0.8.0'} + dependencies: + encodeurl: 1.0.2 + escape-html: 1.0.3 + parseurl: 1.3.3 + send: 0.17.2 + dev: false + + /setprototypeof/1.2.0: + resolution: {integrity: sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==} + dev: false + + /source-map-js/1.0.2: + resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} + engines: {node: '>=0.10.0'} + dev: true + + /sourcemap-codec/1.4.8: + resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==} + dev: false + + /statuses/1.5.0: + resolution: {integrity: sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=} + engines: {node: '>= 0.6'} + dev: false + + /supports-preserve-symlinks-flag/1.0.0: + resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} + engines: {node: '>= 0.4'} + dev: true + + /toidentifier/1.0.1: + resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} + engines: {node: '>=0.6'} + dev: false + + /typescript/4.5.5: + resolution: {integrity: sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: true + + /universalify/2.0.0: + resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==} + engines: {node: '>= 10.0.0'} + dev: false + + /vite/2.8.0: + resolution: {integrity: sha512-ed5rjyeysttuPJX/aKSA0gTB/8ZKLM5xF6FtEuKy1B9DiQbDNFMVMQxnb9JesgBPUMMIJxC8w5KZ/KNWLKFXoA==} + engines: {node: '>=12.2.0'} + hasBin: true + peerDependencies: + less: '*' + sass: '*' + stylus: '*' + peerDependenciesMeta: + less: + optional: true + sass: + optional: true + stylus: + optional: true + dependencies: + esbuild: 0.14.21 + postcss: 8.4.6 + resolve: 1.22.0 + rollup: 2.67.1 + optionalDependencies: + fsevents: 2.3.2 + dev: true diff --git a/src/env.d.ts b/src/env.d.ts new file mode 100644 index 0000000..8baa13b --- /dev/null +++ b/src/env.d.ts @@ -0,0 +1 @@ +declare module 'rollup-plugin-external-globals' \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..f9ed8c6 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,163 @@ +import fs from 'fs-extra'; +import path from 'path'; +import externalGlobals from 'rollup-plugin-external-globals'; +import serveStatic from 'serve-static'; +import { HtmlTagDescriptor, normalizePath, Plugin, UserConfig } from 'vite'; + +interface VitePluginCesiumOptions { + /** + * rebuild cesium library, default: false + */ + rebuildCesium?: boolean; + devMinifyCesium?: boolean; +} + +function vitePluginCesium( + options: VitePluginCesiumOptions = { + rebuildCesium: false, + devMinifyCesium: false + } +): Plugin { + const { rebuildCesium, devMinifyCesium } = options; + + const cesiumBuildRootPath = 'node_modules/mars3d-cesium/Build'; + const cesiumBuildPath = cesiumBuildRootPath + '/Cesium/'; + const mars3dBuildPath = 'node_modules/mars3d/dist/'; + + let CESIUM_BASE_URL = '/cesium/'; + let MARS3D_BASE_URL = '/mars3d/'; + let outDir = 'dist'; + let base: string = '/'; + let isBuild: boolean = false; + + return { + name: 'vite-plugin-ice-mars3d', + + config(c, { command }) { + isBuild = command === 'build'; + if (c.base) { + base = c.base; + if (base === '') base = './'; + } + if (c.build?.outDir) { + outDir = c.build.outDir; + } + CESIUM_BASE_URL = path.posix.join(base, CESIUM_BASE_URL); + const userConfig: UserConfig = {}; + if (!isBuild) { + // -----------dev----------- + userConfig.optimizeDeps = { + exclude: ['mars3d-cesium'] + }; + userConfig.define = { + CESIUM_BASE_URL: JSON.stringify(path.posix.join(base, "mars3d-cesium")) + // MARS3D_BASE_URL: JSON.stringify(path.posix.join(base, "mars3d")) + }; + } else { + // -----------build------------ + if (rebuildCesium) { + // build 1) rebuild cesium library + userConfig.build = { + assetsInlineLimit: 0, + chunkSizeWarningLimit: 5000, + rollupOptions: { + output: { + intro: `window.CESIUM_BASE_URL = "${CESIUM_BASE_URL}";` + } + } + }; + } else { + // build 2) copy Cesium.js later + userConfig.build = { + rollupOptions: { + external: ['cesium','mars3d'], + plugins: [externalGlobals({ cesium: 'Cesium' }),externalGlobals({ mars3d: 'mars3d' })] + } + }; + } + } + return userConfig; + }, + + configureServer({ middlewares }) { + const cesiumPath = path.join( + cesiumBuildRootPath, + devMinifyCesium ? 'Cesium' : 'CesiumUnminified' + ); + middlewares.use(CESIUM_BASE_URL, serveStatic(cesiumPath)); + }, + + async closeBundle() { + if (isBuild) { + try { + await fs.copy( + path.join(cesiumBuildPath, 'Assets'), + path.join(outDir, 'cesium/Assets') + ); + await fs.copy( + path.join(cesiumBuildPath, 'ThirdParty'), + path.join(outDir, 'cesium/ThirdParty') + ); + await fs.copy( + path.join(cesiumBuildPath, 'Workers'), + path.join(outDir, 'cesium/Workers') + ); + await fs.copy( + path.join(cesiumBuildPath, 'Widgets'), + path.join(outDir, 'cesium/Widgets') + ); + if (!rebuildCesium) { + await fs.copy( + path.join(cesiumBuildPath, 'Cesium.js'), + path.join(outDir, 'cesium/Cesium.js') + ); + }; + await fs.copy( + path.join(mars3dBuildPath, ''), + path.join(outDir, 'mars3d') + ); + } catch (err) { + console.error('copy failed', err); + } + } + }, + + transformIndexHtml() { + const tags: HtmlTagDescriptor[] = [ + { + tag: 'link', + attrs: { + rel: 'stylesheet', + href: normalizePath( + path.join(CESIUM_BASE_URL, 'Widgets/widgets.css') + ) + } + }, + { + tag: 'link', + attrs: { + rel: 'stylesheet', + href: normalizePath( + path.join(MARS3D_BASE_URL, 'mars3d.css') + ) + } + } + ]; + if (isBuild && !rebuildCesium) { + tags.push({ + tag: 'script', + attrs: { src: normalizePath(path.join(base, 'cesium/Cesium.js')) } + }); + } + if (isBuild) { + tags.push({ + tag: 'script', + attrs: { src: normalizePath(path.join(MARS3D_BASE_URL, 'mars3d.js')) } + }); + } + return tags; + } + }; +} + +export default vitePluginCesium; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..9e479cf --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "@tsconfig/node12/tsconfig.json", + "include": [ + "src" + ], + "compilerOptions": { + "outDir": "dist", + "declaration": true, + "removeComments": false, + }, +} \ No newline at end of file