Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: Move to vite for build, runtime, tests #939

Closed
wants to merge 9 commits into from
Prev Previous commit
frontend: Try to use remote EmbeddedApp
  • Loading branch information
malinskibeniamin committed Jan 3, 2024
commit 46f3bbead112f0eebece7b10944a5db99b711e2d
36 changes: 36 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start2": "VITE_CJS_IGNORE_WARNING=true REACT_APP_ENABLED_FEATURES=SINGLE_SIGN_ON,REASSIGN_PARTITIONS vite",
"build": "tsc && npm run lint && vite build",
"build-local-test": "tsc && npm run lint && REACT_APP_BUSINESS=true REACT_APP_CONSOLE_GIT_SHA=abc123 REACT_APP_CONSOLE_GIT_REF=local REACT_APP_BUILD_TIMESTAMP=32503680000 REACT_APP_DEV_HINT=true vite build",
"serve": "vite preview --port 3004",
"serve": "vite preview --port 3004 --strictPort",
"test": "TZ=GMT jest --coverage --watchAll=false",
"test:dev": "TZ=GMT jest --coverage --watchAll",
"lint": "eslint \"./src/**/*.{ts,tsx}\" --cache",
Expand Down Expand Up @@ -66,6 +66,7 @@
"vite-tsconfig-paths": "^4.2.2"
},
"devDependencies": {
"@originjs/vite-plugin-federation": "^1.3.3",
"@swc/helpers": "^0.5.3",
"@swc/jest": "^0.2.29",
"@testing-library/jest-dom": "^6.1.4",
Expand Down
22 changes: 14 additions & 8 deletions frontend/src/EmbeddedApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* by the Apache License, Version 2.0
*/

import { useEffect } from 'react';
import React from 'react';
import { BrowserRouter } from 'react-router-dom';

/* start global stylesheets */
Expand All @@ -27,7 +27,7 @@ import './assets/fonts/kumbh-sans.css';
import { appGlobal } from './state/appGlobal';

import { SetConfigArguments, setup, embeddedAvailableRoutesObservable } from './config';
import HistorySetter from './components/misc/HistorySetter';
// import HistorySetter from './components/misc/HistorySetter';
import AppContent from './components/layout/Content';
import { observer } from 'mobx-react';
import { ChakraProvider, redpandaTheme, redpandaToastOptions } from '@redpanda-data/ui';
Expand All @@ -51,11 +51,17 @@ export interface EmbeddedProps extends SetConfigArguments {
* we don't prematurely render console if the higher-order-component Console.tsx might rerender.
* In the future we might decide to use memo() as well
*/
isConsoleReadyToMount?: boolean;
// isConsoleReadyToMount?: boolean;
}

function EmbeddedApp({ basePath, ...p }: EmbeddedProps) {
useEffect(() => {
console.log('Remote App EmbeddedApp p: ', p);

React.useEffect(() => {
console.log('Remote EmbeddedApp React.useEffect');
}, []);

React.useEffect(() => {
const shellNavigationHandler = (event: Event) => {
const pathname = (event as CustomEvent<string>).detail;
const { pathname: currentPathname } = appGlobal.history.location;
Expand All @@ -75,13 +81,13 @@ function EmbeddedApp({ basePath, ...p }: EmbeddedProps) {

setup(p);

if (!p.isConsoleReadyToMount) {
return null;
}
// if (!p.isConsoleReadyToMount) {
// return null;
// }

return (
<BrowserRouter basename={basePath}>
<HistorySetter />
{/* <HistorySetter /> */}
<ChakraProvider theme={redpandaTheme} toastOptions={redpandaToastOptions}>
<AppContent />
</ChakraProvider>
Expand Down
17 changes: 17 additions & 0 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import svgrPlugin from 'vite-plugin-svgr';
import { createHtmlPlugin } from 'vite-plugin-html';
import tsconfigPaths from 'vite-tsconfig-paths';
import muteWarningsPlugin, { warningsToIgnore } from './vite/muteWarningsPlugin';

import federation from '@originjs/vite-plugin-federation';

const ENV_PREFIX = 'REACT_APP_';

// https://vitejs.dev/config/
Expand All @@ -36,6 +39,14 @@ export default defineConfig(({ mode }) => {
}
}
}),
federation({
name: 'remote_app',
filename: 'remoteEntry.js',
exposes: {
'./EmbeddedApp': './src/EmbeddedApp',
},
shared: ['react', 'react-dom']
}),
envCompatible({ prefix: ENV_PREFIX }),
checker({
overlay: false,
Expand Down Expand Up @@ -80,6 +91,12 @@ export default defineConfig(({ mode }) => {
build: {
outDir: 'build',
sourcemap: true,
modulePreload: {
polyfill: false,
},
target: 'esnext',
minify: false,
cssCodeSplit: false,
// TODO: we need to look at how Vite/Rollup sets source maps vs CRA.
// Can we differentiate between production vs dev build?
},
Expand Down
Loading