From bf40546ea42eeeec415fc17fa883f0a840aec100 Mon Sep 17 00:00:00 2001 From: dilesoft Date: Thu, 12 Dec 2024 23:25:00 +0300 Subject: [PATCH] module federation --- src-editor/package.json | 2 +- src-editor/src/index.tsx | 64 ++++++++++++++++++++++++++++++++++++++- src-editor/vite.config.ts | 7 +++-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src-editor/package.json b/src-editor/package.json index dc5dd671..6558bc8c 100644 --- a/src-editor/package.json +++ b/src-editor/package.json @@ -50,7 +50,7 @@ "sass": "^1.82.0", "styled-components": "^6.1.13", "suncalc2": "^1.8.1", - "vite": "^6.0.3", + "vite": "5.2.10", "vite-plugin-commonjs": "^0.10.4", "vite-plugin-svgr": "^4.3.0", "vite-tsconfig-paths": "^5.1.4" diff --git a/src-editor/src/index.tsx b/src-editor/src/index.tsx index 9b1f474a..c79d16ab 100644 --- a/src-editor/src/index.tsx +++ b/src-editor/src/index.tsx @@ -1 +1,63 @@ -void import('./bootstrap'); +import React from 'react'; +import { createRoot } from 'react-dom/client'; + +import './index.css'; +import App from './App'; +import * as serviceWorker from './serviceWorker'; +import pgk from '../package.json'; +import { DndProvider } from 'react-dnd'; +import { HTML5Backend } from 'react-dnd-html5-backend'; +import { TouchBackend } from 'react-dnd-touch-backend'; + +import { GenericBlock } from './Components/RulesEditor/components/GenericBlock'; + +declare global { + interface Window { + GenericBlock: any; + sentryDSN: string; + loadDynamicScript: (url: string, callback: () => void) => void; + socketLoadedHandler: () => void; + } +} +window.GenericBlock = GenericBlock; + +window.adapterName = 'javascript'; +window.sentryDSN = 'https://504499a725eb4898930d3b9e9da95740@sentry.iobroker.net/56'; + +console.log(`iobroker.${window.adapterName}@${pgk.version}`); + +const isMobile = window.innerWidth < 600; +const container = document.getElementById('root'); +if (container) { + const root = createRoot(container); + root.render( + + + , + ); +} + +// If you want your app to work offline and load faster, you can change +// unregister() to register() below. Note this comes with some pitfalls. +// Learn more about service workers: http://bit.ly/CRA-PWA +serviceWorker.unregister(); + +/* + improved VSCode editor. This has to be down here, or we get conflicts + between loader.js and require calls in jQuery and other loaded modules +*/ +// loader must be after socket.io, elsewise there is no window.io +const loadDynamicScript = window.loadDynamicScript; +loadDynamicScript && + loadDynamicScript( + window.location.port === '3000' + ? `${window.location.protocol}//${window.location.hostname}:8081/lib/js/socket.io.js` + : './../../lib/js/socket.io.js', + () => + loadDynamicScript('vs/loader.js', () => + loadDynamicScript( + 'vs/configure.js', + () => typeof window.socketLoadedHandler === 'function' && window.socketLoadedHandler(), + ), + ), + ); diff --git a/src-editor/vite.config.ts b/src-editor/vite.config.ts index 3580e96f..2022d32b 100644 --- a/src-editor/vite.config.ts +++ b/src-editor/vite.config.ts @@ -32,12 +32,15 @@ export default defineConfig({ name: 'iobroker_javascript', remotes: { }, - shared: ([ + shared: makeShared([ 'react', 'react-dom', '@mui/material', '@mui/styles', '@mui/icons-material', 'prop-types', '@iobroker/adapter-react-v5', 'react-ace', ]), }) ], server: { port: 3000 - } + }, + build: { + target: 'chrome89', + }, }); \ No newline at end of file