Skip to content

Commit

Permalink
feat(ui): Migrate to rsbuild from rspack
Browse files Browse the repository at this point in the history
Co-Authored-By: Clark Tomlinson <fallen013@gmail.com>
  • Loading branch information
elliotcourant and th3fallen committed Apr 9, 2024
1 parent 82eb89b commit 19de4f0
Show file tree
Hide file tree
Showing 9 changed files with 1,181 additions and 807 deletions.
6 changes: 3 additions & 3 deletions cmake/NodeModules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else()
set(JS_EXECUTABLE_SUFFIX "")
endif()
set(JEST_EXECUTABLE ${NODE_MODULES_BIN}/jest${JS_EXECUTABLE_SUFFIX})
set(RSPACK_EXECUTABLE ${NODE_MODULES_BIN}/rspack${JS_EXECUTABLE_SUFFIX})
set(RSBUILD_EXECUTABLE ${NODE_MODULES_BIN}/rsbuild${JS_EXECUTABLE_SUFFIX})
set(REACT_EMAIL_EXECUTABLE ${NODE_MODULES_BIN}/email${JS_EXECUTABLE_SUFFIX})
set(NEXT_EXECUTABLE ${NODE_MODULES_BIN}/next${JS_EXECUTABLE_SUFFIX})
set(SITEMAP_EXECUTABLE ${NODE_MODULES_BIN}/next-sitemap${JS_EXECUTABLE_SUFFIX})
Expand All @@ -25,7 +25,7 @@ add_custom_command(
OUTPUT ${NODE_MODULES}
${NODE_MODULES_MARKER}
${JEST_EXECUTABLE}
${RSPACK_EXECUTABLE}
${RSBUILD_EXECUTABLE}
${REACT_EMAIL_EXECUTABLE}
${NEXT_EXECUTABLE}
${SITEMAP_EXECUTABLE}
Expand All @@ -36,7 +36,7 @@ add_custom_command(
BYPRODUCTS ${NODE_MODULES}
${NODE_MODULES_MARKER}
${JEST_EXECUTABLE}
${RSPACK_EXECUTABLE}
${RSBUILD_EXECUTABLE}
${REACT_EMAIL_EXECUTABLE}
${NEXT_EXECUTABLE}
${SITEMAP_EXECUTABLE}
Expand Down
4 changes: 2 additions & 2 deletions compose/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ http {
}

upstream docker-ui {
server ui:30000;
server ui:443;
}

upstream docker-mail {
Expand Down Expand Up @@ -49,7 +49,7 @@ http {
client_max_body_size 5M;
}

location /ws {
location /rsbuild-hmr {
proxy_pass http://docker-ui;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
Expand Down
4 changes: 3 additions & 1 deletion interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ add_custom_command(
# in the output directory.
COMMAND ${GIT_EXECUTABLE} clean -f -X ${UI_DIST_DIR}
# Once the output directory is clean, then actually build the user interface.
COMMAND ${RSPACK_EXECUTABLE} build --mode production
COMMAND ${RSBUILD_EXECUTABLE} build --env-mode production
# Cursed cleanup command because rsbuild was copying this file from fucking narnia
COMMAND ${CMAKE_COMMAND} -E rm ${UI_DIST_DIR}/mockServiceWorker.js
COMMENT "Building monetr's user interface"
WORKING_DIRECTORY ${UI_SRC_DIR}
DEPENDS
Expand Down
16 changes: 9 additions & 7 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "rspack build",
"start": "MONETR_ENV=${MONETR_ENV:=local} rspack serve --mode development",
"build": "rsbuild build",
"start": "MONETR_ENV=${MONETR_ENV:=local} rsbuild dev --env-mode development",
"test": "jest --config=jest.config.ts",
"coverage": "jest --config=jest.config.ts --coverage --coverageDirectory=./reports"
"coverage": "jest --config=jest.config.ts --coverage --coverageDirectory=./reports",
"doctor": "RSDOCTOR=true rsbuild build"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -43,7 +44,6 @@
"date-fns": "2.30.0",
"formik": "2.4.5",
"input-otp": "1.2.3",
"lodash": "4.17.21",
"lucide-react": "0.363.0",
"notistack": "3.0.1",
"path-to-regexp": "6.2.1",
Expand All @@ -67,9 +67,11 @@
"zustand": "4.1.4"
},
"devDependencies": {
"@rspack/binding-linux-arm64-gnu": "0.3.6",
"@rspack/binding-linux-x64-gnu": "0.3.6",
"@rspack/cli": "0.3.6",
"@rsbuild/core": "0.5.9",
"@rsbuild/plugin-react": "0.5.9",
"@rsdoctor/rspack-plugin": "0.1.9",
"@rspack/binding-linux-arm64-gnu": "0.5.9",
"@rspack/binding-linux-x64-gnu": "0.5.9",
"@swc/core": "1.3.95",
"@swc/jest": "0.2.29",
"@testing-library/jest-dom": "5.16.5",
Expand Down
94 changes: 94 additions & 0 deletions interface/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { defineConfig, type RsbuildConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import path from 'path';

export default defineConfig(({ envMode }) => {
const envName = envMode ?? 'development';
const isDevelopment = envName === 'development';
console.log(`environment: ${envName}`);


// Make it so that the websocket still works if we are running yarn start normally.
const wsProto = process.env.WS_PROTO || 'ws';
let websocketUrl = `${wsProto}://monetr.local/ws`;

// This is used for GitPod and CodeSpaces editor environments. Allowing hot reloading when working in the cloud.
if (process.env.CLOUD_MAGIC === 'magic' && process.env.MONETR_UI_DOMAIN_NAME) {
websocketUrl = `${wsProto}://${ process.env.MONETR_UI_DOMAIN_NAME }/ws`;
}

return {
source: {
entry: {
index: './src/index.tsx',
},
alias: {
'@monetr/interface': path.resolve(__dirname, 'src'),
},
define: {
CONFIG: JSON.stringify({}),
REVISION: JSON.stringify(process.env.RELEASE_REVISION),
RELEASE: JSON.stringify(process.env.RELEASE_VERSION),
NODE_VERSION: process.version,
},
},
dev: {
progressBar: true,
client: {
protocol: wsProto as 'wss' | 'ws',
host: 'monetr.local',
port: '443',
},
},
server: {
port: 443,
host: '0.0.0.0',
},
plugins: [pluginReact()],
html: {
template: 'public/index.html',
favicon: 'public/favicon.ico',
templateParameters: {
// When we are doing local dev then don't use anything, maybe use an env var in the future but thats it. But
// for a production build add the go template string in so that the server can provide the DSN.
SENTRY_DSN: isDevelopment ? '' : '{{ .SentryDSN }}',
},
},
output: {
minify: {
jsOptions: {
mangle: false,
},
},
targets: ['web'],
assetPrefix: '/',
cleanDistPath: true,
distPath: {
root: '../server/ui/static',
js: 'assets/scripts',
css: 'assets/styles',
font: 'assets/fonts',
},
copy: {
patterns: [
{
from: 'public/logo192.png',
to: 'logo192.png',
},
{
from: 'public/manifest.json',
to: 'manifest.json',
},
{
from: 'public/logo512.png',
to: 'logo512.png',
},
{
from: 'public/robots.txt',
to: 'robots.txt',
},
],
},
},
} satisfies RsbuildConfig;
});
Loading

0 comments on commit 19de4f0

Please sign in to comment.