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

Redesign the dev server, decouple with Modern.js server #3

Closed
Tracked by #1
chenjiahan opened this issue Oct 9, 2023 · 1 comment
Closed
Tracked by #1

Redesign the dev server, decouple with Modern.js server #3

chenjiahan opened this issue Oct 9, 2023 · 1 comment
Assignees
Labels
✨ enhancement New feature or request

Comments

@chenjiahan
Copy link
Member

chenjiahan commented Oct 9, 2023

Rsbuild should avoid depending on Modern.js packages, so we need to design a new dev server for Rsbuild, and allow Modern.js to replace the builtin dev server.

@9aoy
Copy link
Contributor

9aoy commented Nov 8, 2023

The goal of Rsbuild Server is to be lightweight, simple, and easy to expand:

  • Provide dev/preview capability for rsbuild application
  • Meet the general configuration capabilities used when starting an application (such as setMiddleware, hmrClient, historyApiFallback,etc).
  • Support the expansion of server capabilities to meet the complex needs of upper-level frameworks (such as modern.js) for servers

Detail Design

Rsbuild Server uses a minimalist combination of http + connect , with all built-in/extended logic added via middleware.

var connect = require('connect');
var http = require('http');
 
var app = connect();

app.use(function (req, res, next) {
  // req is the Node.js http request object
  // res is the Node.js http response object
  // next is a function to call to invoke the next middleware
})

//create node.js http server and listen on port
http.createServer(app).listen(3000);

devServers comparison:

Rsbuild DevServer Modern.js DevServer (old) webpack-dev-server
Middleware mode connect modern.js custom express
Relationship with prodServer Shared Middleware DevServer inherits prodServer No prodServer
depends on route.json ✔️ (depends on route.json and routing Middleware)
support custom middlewares ✔️ ✔️ ✔️
support custom plugins ✔️
support static directories ✔️ ✔️
ssr support ✔️
proxy support ✔️ ✔️ ✔️

Breaking changes

Compared to modern.js builder, breaking changes include:

  • Only match file based on static file paths. For example, if you want to access the page through /, you need to ensure that the html output path is dist/index.html
  • SPA and multi-entry SPA are not supported by default, this can be achieved by configuring tools.devServer.historyApiFallback
  • tools.devServer.before/after configuration is not supported, you can use tools.devServer.setupMiddlewares instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants