fix path when vite root change
This commit is contained in:
13
src/index.ts
13
src/index.ts
@@ -5,18 +5,23 @@ import fs from 'fs-extra';
|
|||||||
export default function (): Plugin {
|
export default function (): Plugin {
|
||||||
|
|
||||||
const cesiumBuildPath = 'node_modules/cesium/Build/Cesium/';
|
const cesiumBuildPath = 'node_modules/cesium/Build/Cesium/';
|
||||||
|
let publicPath = 'public';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'vite-plugin-cesium',
|
name: 'vite-plugin-cesium',
|
||||||
|
|
||||||
|
configResolved(resolvedConfig) {
|
||||||
|
publicPath = resolvedConfig.publicDir;
|
||||||
|
},
|
||||||
|
|
||||||
async buildStart(options) {
|
async buildStart(options) {
|
||||||
try {
|
try {
|
||||||
const exists = await fs.pathExists('public/cesium/Assets');
|
const exists = await fs.pathExists('public/cesium/Assets');
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
await fs.copy(path.join(cesiumBuildPath, 'Assets'), 'public/cesium/Assets');
|
await fs.copy(path.join(cesiumBuildPath, 'Assets'), path.join(publicPath, 'cesium/Assets'));
|
||||||
await fs.copy(path.join(cesiumBuildPath, 'ThirdParty'), 'public/cesium/ThirdParty');
|
await fs.copy(path.join(cesiumBuildPath, 'ThirdParty'), path.join(publicPath, 'cesium/ThirdParty'));
|
||||||
await fs.copy(path.join(cesiumBuildPath, 'Workers'), 'public/cesium/Workers');
|
await fs.copy(path.join(cesiumBuildPath, 'Workers'), path.join(publicPath, 'cesium/Workers'));
|
||||||
await fs.copy(path.join(cesiumBuildPath, 'Widgets'), 'public/cesium/Widgets');
|
await fs.copy(path.join(cesiumBuildPath, 'Widgets'), path.join(publicPath, 'cesium/Widgets'));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Reference in New Issue
Block a user