Electron Forge + ViteでエントリーポイントのHTML以外のHTMLでスクリプトを読み込みたいです。

実現したいこと

Electron Forge + Vite でメインウィンドウ以外のHTMLで.mtsスクリプトを読み込みたい。

前提

https://www.electronforge.io/
を参考に、

command

1npm init electron-app@latest my-app -- --template=vite-typescript

を実行してテンプレートを作成しました。
その上で、既存の手動でビルドしていたtypescriptのコードをElectrom Forgeに移行しようとしているのですが、エントリーポイントのHTMLからtsを読み込んでくれるのですが、他のウィンドウのHTMLからtsを読み込んでくれません。
Inspectorを見るとトランスパイルさえしてくれていなくて、jsファイルも吐き出されていないようです。

render側のエラー

1Failed to load resource: net::ERR_FILE_NOT_FOUND

src以下のディレクトリ

1. 2├── @types 3│ ├── preload.d.ts 4│ └── types.d.ts 5├── main_process 6│ ├── main.mts 7│ └── window_handler.mts 8├── preload_script 9│ └── preload.ts 10├── public 11│ └── assets 12│ ├── NoFileChosen.png 13│ └── NoImage.001.png 14├── renderer_process 15│ ├── common_modules.mts 16│ ├── index.mts 17│ └── insert_vehicleAttributes.mts 18└── types.d.ts 19index.htmlはルートディレクトリ直下にあります。 20insert_vehicleAttributes.htmlはルートディレクトリ直下のhtml/insert_vehicleAttributes.htmlです。

insert_vehicleAttributes.htmlから./src/renderer_process/insert_vehicleAttributes.mtsをトランスパイルされたものを読み込みたいです。

発生している問題・エラーメッセージ

mainプロセスのログを見てみるとこのような文言がありました。

(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling.

RollupOptionsまたはHTMLからauto_determineエントリーポイントできませんでした。
そして、明確なoptimizeDeps.includeパターンが存在しません。
依存関係プレビルディングをスキップしました。

該当のソースコード

HTML

1絶対パスで指定しています。 2<script type="module" src="/Users/User Name/Documents/drive-me-20231202/drive-me/src/renderer_process/insert_vehicleAttributes"></script>

vite.renderer.config.ts

1import { defineConfig } from 'vite'; 2import path from "path"; 3 4// https://vitejs.dev/config 5export default defineConfig({ 6 build: { 7 outDir: ".vite/build", 8 emptyOutDir: true, 9 rollupOptions: { 10 input: { 11 insert_vehicleAttributes: path.resolve(__dirname, "src/renderer_process/insert_vehicleAttributes.mts"), 12 } 13 } 14 }, 15 resolve: { 16 alias: { 17 "@renderer": path.resolve(__dirname, "src/renderer_process"), 18 } 19 } 20});

イメージ説明

試したこと

build.rollupOptions.inputに項目を追加してみました。
エントリーポイントのHTMLでは絶対パスでトランスパイルされたtsを読めていたので、他のHTMLも絶対パスで指定してみました。
npm startでビルド・実行しています。

補足情報(FW/ツールのバージョンなど)

MacOS: 14.1.2 (23B92)

package.json

1{ 2 "name": "drive-me", 3 "productName": "drive-me", 4 "version": "0.1.0", 5 "description": "The \"drive-me\" is a comprehensive tool designed to efficiently manage the operational status and attributes of rental cars. This app provides an intuitive platform for monitoring and organizing vital information related to the fleet of vehicles.", 6 "main": ".vite/build/main.js", 7 "scripts": { 8 "start": "electron-forge start", 9 "package": "electron-forge package", 10 "make": "electron-forge make", 11 "publish": "electron-forge publish", 12 "lint": "eslint --ext .ts,.tsx ." 13 }, 14 "keywords": [], 15 "author": "User Name", 16 "license": "MIT", 17 "devDependencies": { 18 "@electron-forge/cli": "^7.2.0", 19 "@electron-forge/maker-deb": "^7.2.0", 20 "@electron-forge/maker-rpm": "^7.2.0", 21 "@electron-forge/maker-squirrel": "^7.2.0", 22 "@electron-forge/maker-zip": "^7.2.0", 23 "@electron-forge/plugin-auto-unpack-natives": "^7.2.0", 24 "@electron-forge/plugin-vite": "^7.2.0", 25 "@typescript-eslint/eslint-plugin": "^5.0.0", 26 "@typescript-eslint/parser": "^5.0.0", 27 "electron": "27.1.3", 28 "eslint": "^8.0.1", 29 "eslint-import-resolver-typescript": "^3.6.1", 30 "eslint-plugin-import": "^2.25.0", 31 "ts-node": "^10.0.0", 32 "typescript": "~4.5.4" 33 }, 34 "dependencies": { 35 "axios": "^1.6.2", 36 "dotenv": "^16.3.1", 37 "electron-squirrel-startup": "^1.0.0" 38 } 39} 40 41VSCode: 42Version: 1.84.2 (Universal) 43Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e 44Date: 2023-11-09T10:52:33.687Z (3 wks ago) 45Electron: 25.9.2 46ElectronBuildId: 24603566 47Chromium: 114.0.5735.289 48Node.js: 18.15.0 49V8: 11.4.183.29-electron.0 50OS: Darwin arm64 23.1.0

コメントを投稿

0 コメント