fix(vite配置): 修正publicDir设置并更新demo页面逻辑

将publicDir从false改为'public'以正确访问静态资源
更新demo.html默认加载逻辑,自动指向/test.ocd并修改iframe引用为vocd.html
This commit is contained in:
hanshiyang 2025-11-28 15:54:46 +08:00
parent 37e4e4cc6a
commit 0f0eca6128
2 changed files with 17 additions and 6 deletions

View File

@ -18,18 +18,28 @@
<div class="panel">
<input id="urlInput" type="text" placeholder="输入同源文件URL" />
<button id="loadBtn">设置 iframe 地址</button>
<small>仅拼接 iframe srcindex.html?filePath=URL&mode=edit</small>
<small>仅拼接 iframe srcvocd.html?filePath=URL&mode=edit</small>
</div>
<iframe id="editorFrame" src="./index.html" referrerpolicy="no-referrer"></iframe>
<iframe id="editorFrame" src="./vocd.html" referrerpolicy="no-referrer"></iframe>
<script>
const editorFrame = document.getElementById('editorFrame')
const loadBtn = document.getElementById('loadBtn')
const urlInput = document.getElementById('urlInput')
// 页面加载后,自动将 iframe 指向 vocd.html 并使用同源 /test.ocd
document.addEventListener('DOMContentLoaded', () => {
const defaultUrl = '/test.ocd' // 来自 public同源可直接访问
urlInput.value = defaultUrl
const base = './vocd.html'
const src = `${base}?filePath=${encodeURIComponent(defaultUrl)}&mode=edit`
editorFrame.src = src
console.log('[demo] 自动设置 iframe src:', src)
})
loadBtn.onclick = () => {
const typedUrl = urlInput.value.trim()
const base = './index.html'
const base = './vocd.html'
const src = typedUrl
? `${base}?filePath=${encodeURIComponent(typedUrl)}&mode=edit`
: `${base}?mode=edit`
@ -38,4 +48,4 @@
}
</script>
</body>
</html>
</html>

View File

@ -39,7 +39,7 @@ export default defineConfig(({ mode }) => {
}
return {
base: './',
publicDir: false,
publicDir: 'public',
build: {
rollupOptions: {
input: {
@ -48,7 +48,8 @@ export default defineConfig(({ mode }) => {
}
},
server: {
host: '0.0.0.0'
host: '0.0.0.0',
open: '/demo.html'
}
}
})