add pwa in nextjs

This commit is contained in:
Aman Varshney
2025-05-21 13:02:58 +05:30
parent cd8b5a9db4
commit 01d745a3e5
15 changed files with 83 additions and 11 deletions

View File

@@ -10,7 +10,9 @@ import type { ProjectConfig } from "../types";
export async function setupAddons(config: ProjectConfig) {
const { addons, frontend, projectDir } = config;
const hasReactWebFrontend =
frontend.includes("react-router") || frontend.includes("tanstack-router");
frontend.includes("react-router") ||
frontend.includes("tanstack-router") ||
frontend.includes("next");
const hasNuxtFrontend = frontend.includes("nuxt");
const hasSvelteFrontend = frontend.includes("svelte");
const hasSolidFrontend = frontend.includes("solid");

View File

@@ -557,10 +557,20 @@ export async function setupAddonsTemplate(
let addonDestDir = projectDir;
if (addon === "pwa") {
addonSrcDir = path.join(PKG_ROOT, "templates/addons/pwa/apps/web");
addonDestDir = path.join(projectDir, "apps/web");
if (!(await fs.pathExists(addonDestDir))) {
const webAppDir = path.join(projectDir, "apps/web");
if (!(await fs.pathExists(webAppDir))) {
continue;
}
addonDestDir = webAppDir;
if (context.frontend.includes("next")) {
addonSrcDir = path.join(PKG_ROOT, "templates/addons/pwa/apps/web/next");
} else if (
context.frontend.some((f) =>
["tanstack-router", "react-router", "solid"].includes(f),
)
) {
addonSrcDir = path.join(PKG_ROOT, "templates/addons/pwa/apps/web/vite");
} else {
continue;
}
}

View File

@@ -800,7 +800,10 @@ function processAndValidateFlags(
);
const hasCompatibleWebFrontend = effectiveFrontend?.some((f) => {
const isPwaCompatible =
f === "tanstack-router" || f === "react-router" || f === "solid";
f === "tanstack-router" ||
f === "react-router" ||
f === "solid" ||
f === "next";
const isTauriCompatible =
f === "tanstack-router" ||
f === "react-router" ||
@@ -828,7 +831,7 @@ function processAndValidateFlags(
let incompatibleReason = "Selected frontend is not compatible.";
if (config.addons.includes("pwa")) {
incompatibleReason =
"PWA requires tanstack-router, react-router, or solid.";
"PWA requires tanstack-router, react-router, next, or solid.";
}
if (config.addons.includes("tauri")) {
incompatibleReason =

View File

@@ -18,7 +18,8 @@ export async function getAddonsChoice(
const hasCompatiblePwaFrontend =
frontends?.includes("react-router") ||
frontends?.includes("tanstack-router") ||
frontends?.includes("solid");
frontends?.includes("solid") ||
frontends?.includes("next");
const hasCompatibleTauriFrontend =
frontends?.includes("react-router") ||