Skip to content

Commit

Permalink
webpack -> rspack migration (#388)
Browse files Browse the repository at this point in the history
* migrate to rspack when bundling the web app

* fix incorrect supervisord.conf

* temporary edit of the tests, to point to the edited version of the template app

* clone the modified branch directly

* add some documentation about the web app bundling

* point to baselayer template apps main branch
  • Loading branch information
Theodlz authored Oct 3, 2024
1 parent 1a34132 commit 8f6d1dc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ B=\033[1m
N=\033[0m

bundle = static/build/main.bundle.js
webpack = npx webpack
rspack = npx rspack

# NOTE: These targets are meant to be *included* in the parent app
# Makefile. See end of this file for baselayer specific targets.
Expand Down Expand Up @@ -55,13 +55,13 @@ db_clear: ## Delete all data from the database.
db_clear: dependencies
@PYTHONPATH=. baselayer/tools/silent_monitor.py baselayer/tools/db_init.py -f $(FLAGS)

$(bundle): webpack.config.js package.json
@$(webpack)
$(bundle): rspack.config.js package.json
@$(rspack)

bundle: $(bundle)

bundle-watch:
$(webpack) -w
$(rspack) -w

paths:
@mkdir -p log run tmp
Expand Down
4 changes: 4 additions & 0 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ Sometimes, the supervisor configuration needs information from the
configuration file, therefore `supervisor.conf` can instead be
provided as `supervisor.conf.template`, which will be compiled before
launching. See, e.g., `services/dask`.

## Web Application

Baselayer comes with a microservice capable of bundling a web application. A great example of this is given in the [template application](https://github.com/cesium-ml/baselayer_template_app). When building your own application on top of baselayer, you'll need to add your own `static` directory at the root of your project, as well as a `rspack.config.js` file to bundle your application. The `rspack.config.js` from the template application is a good starting point, and will be sufficient for most use cases. Instead of using the very popular [webpack](https://webpack.js.org/), we use [rspack](https://rspack.dev/) as a 1:1 replacement. It covers all the features needed by baselayer, but offers much faster build times in development and production modes. We've noticed a x2 speedup on average when building a complex & heavy web app such as [SkyPortal](https://github.com/skyportal/skyportal), and at least a x5 speedup when re-building the app in watch mode, which we use to update the web app in real-time when developing.
8 changes: 4 additions & 4 deletions services/webpack/webpack.py → services/rspack/rspack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from baselayer.app.env import load_env, parser
from baselayer.log import make_log

parser.description = "Launch webpack microservice"
parser.description = "Launch rspack microservice"

env, cfg = load_env()

log = make_log("service/webpack")
log = make_log("service/rspack")


def run(cmd):
Expand All @@ -19,8 +19,8 @@ def run(cmd):


if env.debug:
log("Debug mode detected, launching webpack monitor")
p = run(["npx", "webpack", "--watch"])
log("Debug mode detected, launching rspack monitor")
p = run(["npx", "rspack", "--watch"])
sys.exit(p.returncode)
else:
log("Production mode; not building JavaScript bundle")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## For development only: do not run in production

[program:webpack]
command=/usr/bin/env python baselayer/services/webpack/webpack.py %(ENV_FLAGS)s
[program:rspack]
command=/usr/bin/env python baselayer/services/rspack/rspack.py %(ENV_FLAGS)s
environment=PYTHONPATH=".",PYTHONUNBUFFERED="1"
startretries=0
startsecs=0
stdout_logfile=log/webpack.log
stdout_logfile=log/rspack.log
redirect_stderr=true
stopasgroup=true
# Start this before any other services; it takes a while to build the bundle
Expand Down
2 changes: 1 addition & 1 deletion tools/supervisor_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def supervisor_status():
int
Return code of ``supervisorctl``. This will be 0 for all
services running, or 3 if one of them exited (note: this is
expected when, e.g., webpack exits normally).
expected when, e.g., rspack exits normally).
"""
result = subprocess.run(
"python -m supervisor.supervisorctl -c baselayer/conf/supervisor/supervisor.conf status",
Expand Down
2 changes: 1 addition & 1 deletion tools/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def verify_server_availability(url, timeout=180):
)
response = requests.get(url + "/static/build/main.bundle.js")
assert response.status_code == 200, (
"Javascript bundle not found," " did Webpack fail?"
"Javascript bundle not found," " did rspack fail?"
)
return # all checks passed
except Exception as e:
Expand Down

0 comments on commit 8f6d1dc

Please sign in to comment.