web-infra-dev / rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.
https://rsbuild.dev/
MIT License
1.59k stars 126 forks source link

[Feature]: When using HTTPS, it defaults to using a self-signed certificate. #2175

Closed nanianlisao closed 5 months ago

nanianlisao commented 5 months ago

What problem does this feature solve?

I think it should be like webpack-dev-server; for most scenarios, a self-signed certificate should suffice.

Moreover, I believe that mkcert presents a certain level of initial learning curve for developers' local environments. Therefore, I think integrating a self-signed certificate might also be a better approach.

What does the proposed API look like?

The external API remains as usual, except that the server.https configuration supports a boolean.

When set to true or when cert and key do not exist, it will automatically create and use a self-signed certificate.

export default defineConfig({
  server: {
    https: true
  }
});

Of course, self-signed certificates indeed have issues with browser trust, but I think the framework leans more towards being usable out of the box. We can still recommend users to use mkcert, but internally, there should be a fallback solution.

chenjiahan commented 5 months ago

This can be supported by a standalone Rsbuild plugin, like https://www.npmjs.com/package/@vitejs/plugin-basic-ssl

nanianlisao commented 5 months ago

I might not quite agree with the view that it should be made into a separate plugin.

First of all, npm packages like selfsigned already have the capability to accomplish similar functions, so creating a separate plugin might not offer significant benefits.

Moreover, for rsbuild, this seems to be only related to the dev-server, hence I believe it should simply be implemented as a util function within the dev-server itself.