无法在第三方工具 iframe 中预览使用 Vite 开发的 Vue 应用(但可以使用 Vue CLI)

发布于 2025-01-14 14:25:01 字数 348 浏览 1 评论 0原文

我正在开发一个 Vue 应用程序,它将被“iframed”到第 3 方框架中。我可以在 localhost 下本地开发我的应用程序,但为了在第 3 方工具中预览它,URL 应为:https://localhost:5001/sampleapp/index.html

我有同一个应用程序的两个版本。第一个是使用 Vue-CLI 构建的,第二个是使用 Vite 构建的。

当我尝试预览应用程序的 Vite 版本时,我看到一个空白页面。

当使用 Vue CLI 版本时,我得到了一个可以工作的应用程序,并且可以像平常一样开发它,并且它在 iframe 中“热重载”。

如何使用 Vite 实现同样的效果?

I am developing a Vue app that will be "iframed" into a 3rd party framework. I can develop my app locally under the localhost, but in order to preview it in the 3rd party tool, the URL should be: https://localhost:5001/sampleapp/index.html.

I have two versions of the same app. One was built with Vue-CLI and the 2nd one with Vite.

When I try to preview the Vite version of the app, I get a blank page.

When using Vue CLI version, I get a working app and can develop it as I would normally do, and it 'hot-reloads' in the iframe.

How do I achieve the same with Vite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笏见 2025-01-21 14:25:01

@edytajordan 的回答:

事实证明,对于 Vite 版本,我实际上必须在预览模式下运行应用程序。我的最终 vite.config.js:

export default defineConfig({
  plugins: [vue()],
  base: '/sampleapp/index.html/',
  server: {
    port: 5001,
    https: true,
  },
  preview: {
    port: 5001,
    https: true,
  }
})

然后运行 ​​npm run build && npm 运行预览。

@edytajordan's answer:

It turned out, that for the Vite version, I actually had to run the App in the preview mode. My final vite.config.js:

export default defineConfig({
  plugins: [vue()],
  base: '/sampleapp/index.html/',
  server: {
    port: 5001,
    https: true,
  },
  preview: {
    port: 5001,
    https: true,
  }
})

and then run npm run build && npm run preview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文