electron-vite icon indicating copy to clipboard operation
electron-vite copied to clipboard

Base variable gets ignored

Open FynniX opened this issue 1 year ago • 8 comments
trafficstars

Describe the bug

The base variable inside electron.vite.config.ts gets ignored. The build output always shows a prefix of ./ in front of assets links.

Electron-Vite Version

2.0.0

Electron Version

28.2.0

Vite Version

5.0.12

Validations

FynniX avatar Apr 03 '24 16:04 FynniX

The base option should not be set in Electron. I think your problem is not with this option, but with your project structure and configuration.

alex8088 avatar Apr 04 '24 05:04 alex8088

Maybe your problem is static public assets handling.

alex8088 avatar Apr 04 '24 05:04 alex8088

I see the point you are making here but there are specific application requirements where you would need a http server, so why would you restrict it to not setting the base in that case? The base is still ./ by default in my PR. It would just allow for more range of freedom for the usage of electron-vite.

FynniX avatar Apr 04 '24 10:04 FynniX

I also have this problem. I need to output both web and exe at the same time, so that 'base' can be used normally in the web. Now, both web and exe can run normally, but I need to configure base separately. How should I solve this problem?

TodayCG avatar Apr 08 '24 11:04 TodayCG

base option not work in Electron. The recommended way is to add a vite config with the specified different output directories and use vite to bundle your renderer.

alex8088 avatar Apr 08 '24 11:04 alex8088

I also have this problem. I need to output both web and exe at the same time, so that 'base' can be used normally in the web. Now, both web and exe can run normally, but I need to configure base separately. How should I solve this problem?

I published my fork under https://www.npmjs.com/package/@fynnix/electron-vite, where the base parameter can be changed. I have the same reason as you, where I output something via web and a electron window.

FynniX avatar Apr 08 '24 12:04 FynniX

base option not work in Electron. The recommended way is to add a vite config with the specified different output directories and use vite to bundle your renderer.

Your suggestion should work as long as you dont use something like preact prerendering.

FynniX avatar Apr 08 '24 12:04 FynniX

您好, 我也遇到了类似的问题, 我引用这个工具的目的就是一套代码一次性输出桌面端和Web端, 据我所知, 其中的 renderer可以直接部署到web服务器的(虽然部分功能受限, 但这我会额外处理), 目前由于base不生效, 导致我的nginx配置变得很麻烦 另外我在实践过程中发现可以换一种思路来解决这个问题, 即引入 <base href="/"/> 这对于js和css是生效的, 对于字体库则不生效详见

  <head>
    <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin="anonymous">
    <link rel="preload" as="style" onload="this.rel='stylesheet'" href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&display=swap">
    <!-- 此部分资源无法正常加载, 仍然受地址栏相对路径影响 -->
    <link rel="preload" as="font" type="font/eot" href="assets/materialdesignicons-webfont-CSr8KVlo.eot" crossorigin="anonymous">
    <link rel="preload" as="font" type="font/woff2" href="assets/materialdesignicons-webfont-Dp5v-WZN.woff2" crossorigin="anonymous">
    <link rel="preload" as="font" type="font/woff" href="assets/materialdesignicons-webfont-PXm3-2wK.woff" crossorigin="anonymous">
    <link rel="preload" as="font" type="font/ttf" href="assets/materialdesignicons-webfont-B7mPwVP_.ttf" crossorigin="anonymous">

    <meta charset="UTF-8" />
    <title>桌面端</title>
    <!-- 添加base -->
    <base href="/pc/"/>
    <!-- 此部分资源能够正常加载 -->
    <script type="module" crossorigin src="./assets/index-pfmInVXk.js"></script>
    <link rel="stylesheet" crossorigin href="./assets/index-Z_vj-Phw.css">
  </head>

amulet-faith avatar Aug 03 '24 11:08 amulet-faith