diff --git a/pdm_build.py b/pdm_build.py
index a9a1eb3dc6c526966621cdfbf367f5f0f2c9ef7f..49f4d2592677859fbaa99931f1a585d6d3ea290a 100644
--- a/pdm_build.py
+++ b/pdm_build.py
@@ -12,6 +12,20 @@ if TYPE_CHECKING:
 def pdm_build_initialize(context: Context) -> None:
     if not context.target == "sdist":
         return
+
+    metadata = context.config.metadata
+    name = metadata["name"]
+    optdeps = metadata["optional-dependencies"]
+    groups = dict()
+    for opt in optdeps:
+        group = opt.split("-")[0]
+        if group not in groups:
+            groups[group] = []
+        groups[group].append(opt)
+    for k, v in groups.items():
+        optdeps[f"all-{k}"] = [f"{name}[{','.join(v)}]"]
+    optdeps["all"] = [f"{name}[{','.join('all-' + g for g in groups)}]"]
+
     context.config.build_config.includes.append("schilder2000/static/manifest.json")
     if "without-npm" not in context.config_settings:
         # Assume built webpack is already present otherwise