1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

Update index.ts

Hello @nshen,我今天用这个插件的时候发现了一个问题:

当我在 vite.config.js 中修改 base 后,在 dev 环境下提示找不到 widgets.css,打包后使用 vite preview 查看发现 cesium 的静态资源全都报了 404。我发现引入资源的路径有问题,于是我尝试改了下源码,我又新建了一个 react 和 原生 js 的项目来测试,目前的修改是可用的。
This commit is contained in:
GuTianhuang
2021-09-10 14:19:31 +08:00
committed by GitHub
parent 3f7c92e985
commit 4e474e79d1

View File

@@ -21,7 +21,6 @@ function vitePluginCesium(
const cesiumBuildPath = 'node_modules/cesium/Build/Cesium/';
const CESIUM_BASE_URL = '/cesium/';
let publicPath = 'public';
let outDir = 'dist';
let base: string;
let isBuild: boolean = false;
@@ -30,13 +29,14 @@ function vitePluginCesium(
name: 'vite-plugin-cesium',
config(_, { command }) {
const isBuild = command === 'build'
const userConfig: UserConfig = {
build: {
assetsInlineLimit: 0,
chunkSizeWarningLimit: 4000
},
define: {
CESIUM_BASE_URL: JSON.stringify(CESIUM_BASE_URL)
CESIUM_BASE_URL: JSON.stringify(isBuild ? base + CESIUM_BASE_URL : CESIUM_BASE_URL)
}
};
if (command === 'build' && !rebuildCesium) {
@@ -102,7 +102,7 @@ function vitePluginCesium(
tag: 'link',
attrs: {
rel: 'stylesheet',
href: base + 'cesium/Widgets/widgets.css'
href: isBuild ? base + 'cesium/Widgets/widgets.css' : CESIUM_BASE_URL + 'Widgets/widgets.css'
}
}
];