Skip to content

Commit

Permalink
module federation
Browse files Browse the repository at this point in the history
  • Loading branch information
DileSoft committed Dec 12, 2024
1 parent 9987880 commit bf40546
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
64 changes: 63 additions & 1 deletion src-editor/src/index.tsx
Original file line number Diff line number Diff line change
@@ -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://[email protected]/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(
<DndProvider backend={isMobile ? TouchBackend : HTML5Backend}>
<App version={pgk.version} />
</DndProvider>,
);
}

// 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(),
),
),
);
7 changes: 5 additions & 2 deletions src-editor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});

0 comments on commit bf40546

Please sign in to comment.