[Update/bugfix] Plugins: For development, fix hot reload issue that was restart every time updated the files.
This commit is contained in:
1
src-tauri/plugins/index.js
Normal file
1
src-tauri/plugins/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// This is for preserving plugins folder. It will be detected and created 'plugins' folder to target/debug/ by tauri build. do not delete it.
|
||||||
@@ -10,8 +10,8 @@ import { useStdoutToPython } from "@logics/useStdoutToPython";
|
|||||||
|
|
||||||
import { transform } from "@babel/standalone";
|
import { transform } from "@babel/standalone";
|
||||||
import { writeFile, createDir, exists, removeDir, readDir, BaseDirectory, readTextFile } from "@tauri-apps/api/fs";
|
import { writeFile, createDir, exists, removeDir, readDir, BaseDirectory, readTextFile } from "@tauri-apps/api/fs";
|
||||||
const dev_plugin_mapping = import.meta.glob("/src-tauri/plugins/**/index.jsx", { eager: true });
|
import { dev_plugins } from "@dev_plugins_path";
|
||||||
const dev_plugin_info_mapping = import.meta.glob("/src-tauri/plugins/**/plugin_info.json", { eager: true });
|
|
||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
|
|
||||||
import { useFetch } from "@logics_common";
|
import { useFetch } from "@logics_common";
|
||||||
@@ -85,22 +85,17 @@ export const usePlugins = () => {
|
|||||||
|
|
||||||
const asyncLoadAllPlugins = async () => {
|
const asyncLoadAllPlugins = async () => {
|
||||||
if (import.meta.env.DEV) {
|
if (import.meta.env.DEV) {
|
||||||
// 開発時: ホットリロード対応、src-tauri以下のpluginsから直接読み込み
|
// `dev_plugins` を利用してプラグインを登録
|
||||||
Object.entries(dev_plugin_mapping).forEach(([key, plugin_module]) => {
|
dev_plugins.forEach(({ index, plugin_info }) => {
|
||||||
// 例: key が "/src-tauri/plugins/sample/index.jsx" の場合、plugin_info.json のパスは同じディレクトリ内にある
|
if (!index || !plugin_info) {
|
||||||
const pluginInfoKey = key.replace("index.jsx", "plugin_info.json");
|
console.error("Invalid development plugin detected", index, plugin_info);
|
||||||
const plugin_info = dev_plugin_info_mapping[pluginInfoKey];
|
|
||||||
|
|
||||||
if (!plugin_info) {
|
|
||||||
console.error("plugin_info.json has not found:", pluginInfoKey);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// plugin_info を使ってプラグインコンテキストを生成
|
|
||||||
const plugin_context = generatePluginContext(plugin_info);
|
const plugin_context = generatePluginContext(plugin_info);
|
||||||
|
if (index.init) {
|
||||||
if (plugin_module && plugin_module.init) {
|
index.init(plugin_context);
|
||||||
plugin_module.init(plugin_context);
|
} else {
|
||||||
|
console.error("Plugin missing init function", plugin_info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
9
src-ui/plugins/index.js
Normal file
9
src-ui/plugins/index.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import plugin_index_1 from "./plugin_examples/index.jsx";
|
||||||
|
import plugin_info_1 from "./plugin_examples/plugin_info.json";
|
||||||
|
|
||||||
|
export const dev_plugins = [
|
||||||
|
{
|
||||||
|
index: { init: plugin_index_1 },
|
||||||
|
plugin_info: plugin_info_1,
|
||||||
|
}
|
||||||
|
];
|
||||||
@@ -33,11 +33,6 @@ export default defineConfig(async () => ({
|
|||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"react": path.resolve(__dirname, "node_modules/react"),
|
|
||||||
"react-dom": path.resolve(__dirname, "node_modules/react-dom"),
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"@root": path.resolve(__dirname),
|
"@root": path.resolve(__dirname),
|
||||||
"@test_data": path.resolve(__dirname, "./test_data.js"),
|
"@test_data": path.resolve(__dirname, "./test_data.js"),
|
||||||
|
|
||||||
@@ -53,6 +48,8 @@ export default defineConfig(async () => ({
|
|||||||
|
|
||||||
"@setting_box": path.resolve(__dirname, "src-ui/app/config_page/setting_section/setting_box/index.js"),
|
"@setting_box": path.resolve(__dirname, "src-ui/app/config_page/setting_section/setting_box/index.js"),
|
||||||
"@common_components": path.resolve(__dirname, "src-ui/common_components/index.js"),
|
"@common_components": path.resolve(__dirname, "src-ui/common_components/index.js"),
|
||||||
|
|
||||||
|
"@dev_plugins_path": path.resolve(__dirname, "src-ui/plugins/index.js"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user