Skip to content

Commit

Permalink
chore(deps) & feat: support Next's new logging style, added `PluginOp…
Browse files Browse the repository at this point in the history
…tions.browserslist` (#84)
  • Loading branch information
DuCanhGH authored Sep 16, 2023
1 parent bf131ab commit 12a6542
Show file tree
Hide file tree
Showing 44 changed files with 1,163 additions and 1,006 deletions.
9 changes: 9 additions & 0 deletions .changeset/six-bananas-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ducanh2912/next-pwa": minor
---

feat: added `PluginOptions.browserslist`

- This defaults to `"chrome >= 56"`, same with Workbox's default.
- Note that `.browserslistrc`, `package.json.browserslist`, etc. are not supported (yet), and the only way to pass the config to `next-pwa` is `PluginOptions.browserslist`, but you can read the file yourself, parse it, then pass it to `next-pwa`.
- This allows you to configure which browsers you want to target your workers for. This tells `next-pwa` to add `PluginOptions.workboxOptions.babelPresetEnvTargets` if that option is not defined, which means that the service worker will, too, be bundled to target these browsers, but you can change that by adding the option.
7 changes: 7 additions & 0 deletions .changeset/tall-rocks-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ducanh2912/next-pwa": minor
---

feat: support Next's new logging style

- So Next changed its logging style again, and I'm wondering if trying to match its logging style is even a good idea.
1 change: 0 additions & 1 deletion docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const withPWA = withPWAInit({
const nextConfig = {
output: "export",
experimental: {
appDir: true,
extensionAlias: {
".js": [".js", ".ts", ".tsx"],
},
Expand Down
24 changes: 12 additions & 12 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "workspace:*",
"@mantine/hooks": "6.0.19",
"@tabler/icons-react": "2.32.0",
"@mantine/hooks": "6.0.20",
"@tabler/icons-react": "2.34.0",
"bright": "0.8.4",
"client-only": "0.0.1",
"contentlayer": "0.3.4",
Expand All @@ -23,33 +23,33 @@
"react-wrap-balancer": "1.1.0",
"server-only": "0.0.1",
"tailwind-merge": "1.14.0",
"uuid": "9.0.0",
"uuid": "9.0.1",
"zustand": "4.4.1"
},
"devDependencies": {
"@types/extend": "3.0.1",
"@types/hast": "3.0.0",
"@types/mdast": "4.0.0",
"@types/mdx": "2.0.6",
"@types/node": "20.5.1",
"@types/react": "18.2.20",
"@types/mdx": "2.0.7",
"@types/node": "20.6.1",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"@types/uuid": "9.0.2",
"@types/uuid": "9.0.4",
"autoprefixer": "10.4.15",
"extend": "3.0.2",
"github-slugger": "2.0.0",
"hast-util-has-property": "3.0.0",
"hast-util-heading-rank": "3.0.0",
"hast-util-to-string": "2.0.0",
"hast-util-to-string": "3.0.0",
"mdast-util-mdx": "3.0.0",
"mdast-util-to-markdown": "2.1.0",
"mdast-util-to-string": "4.0.0",
"mdx-bundler": "9.2.1",
"postcss": "8.4.28",
"rehype-highlight": "6.0.0",
"rehype-sanitize": "5.0.1",
"postcss": "8.4.29",
"rehype-highlight": "7.0.0",
"rehype-sanitize": "6.0.0",
"tailwindcss": "3.3.3",
"typescript": "5.3.0-dev.20230822",
"typescript": "5.3.0-dev.20230915",
"unified": "10.1.2",
"unist-util-is": "6.0.0",
"unist-util-visit": "5.0.0"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import Link from "next/link";

import { Button } from "./Button";

export default function Page() {
return (
<>
<h1>This is the basic example.</h1>
<Link href="/appdir">Home page</Link>
<h1>This is the most basic example of using next-pwa.</h1>
<Button />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { Metadata } from "next";
import Link from "next/link";

export const metadata: Metadata = {
title: "Home (appDir)",
title: "Home",
};

export default function Page() {
return (
<>
<h1>Next.js + PWA = AWESOME!</h1>
<Link href="/appdir/about">About page</Link>
<Link href="/about">About page</Link>
</>
);
}
6 changes: 3 additions & 3 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.5.1",
"@types/react": "18.2.20",
"@types/node": "20.6.1",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"typescript": "5.1.6"
"typescript": "5.2.2"
}
}
13 changes: 0 additions & 13 deletions examples/basic/pages/api/hello.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function Home() {
return (
<>
<Head>
<title>next-pwa example | Home</title>
<title>next-pwa example</title>
</Head>
<h1>Next.js + PWA = AWESOME!</h1>
</>
Expand Down
8 changes: 4 additions & 4 deletions examples/custom-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
"@ducanh2912/next-pwa": "latest",
"@fastify/compress": "6.4.0",
"cross-env": "7.0.3",
"fastify": "4.21.0",
"fastify": "4.23.2",
"next": "13.4.19",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@swc/core": "1.3.78",
"@types/node": "20.5.1",
"@types/react": "18.2.20",
"@types/node": "20.6.1",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"nodemon": "3.0.1",
"rimraf": "5.0.1",
"ts-node": "10.9.1",
"typescript": "5.1.6"
"typescript": "5.2.2"
}
}
6 changes: 3 additions & 3 deletions examples/custom-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.5.1",
"@types/react": "18.2.20",
"@types/node": "20.6.1",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"typescript": "5.1.6"
"typescript": "5.2.2"
}
}
54 changes: 54 additions & 0 deletions examples/lifecycle/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { Metadata } from "next";
import type { ReactNode } from "react";

import { PWALifeCycle } from "../components/PWALifecycle";

const APP_NAME = "next-pwa example";
const APP_DESCRIPTION = "This is an example of using next-pwa";

export const metadata: Metadata = {
applicationName: APP_NAME,
title: {
default: APP_NAME,
template: "%s - PWA App",
},
description: APP_DESCRIPTION,
manifest: "/manifest.json",
themeColor: "#FFFFFF",
appleWebApp: {
capable: true,
statusBarStyle: "default",
title: APP_NAME,
},
formatDetection: {
telephone: false,
},
icons: {
shortcut: "/favicon.ico",
apple: [{ url: "/icons/apple-touch-icon.png", sizes: "180x180" }],
},
};

export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en" dir="ltr">
<head>
<style>{`
html, body, #__next {
height: 100%;
}
#__next {
margin: 0 auto;
}
h1 {
text-align: center;
}
`}</style>
</head>
<body>
<PWALifeCycle />
{children}
</body>
</html>
);
}
13 changes: 13 additions & 0 deletions examples/lifecycle/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "next-pwa example",
};

export default function Page() {
return (
<>
<h1>Next.js + PWA = AWESOME!!</h1>
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from "next/head";
"use client";
import { useEffect } from "react";

export default function Index() {
export function PWALifeCycle() {
// This hook only run once in browser after the component is rendered for the first time.
// It has same effect as the old componentDidMount lifecycle callback.
useEffect(() => {
Expand All @@ -27,12 +27,11 @@ export default function Index() {
"A newer version of this web app is available, reload to update?"
)
) {
// Send a message to the waiting service worker, instructing it to activate.
wb.messageSkipWaiting();
wb.addEventListener("controlling", () => {
window.location.reload();
});

// Send a message to the waiting service worker, instructing it to activate.
wb.messageSkipWaiting();
} else {
console.log(
"User rejected to update SW, keeping the old version. New version will be automatically loaded when the app is opened next time."
Expand All @@ -50,17 +49,9 @@ export default function Index() {
console.log(event);
});

// never forget to call register as automatic registration is turned off in next.config.js
// Don't forget to call register as automatic registration is disabled.
wb.register();
}
}, []);

return (
<>
<Head>
<title>next-pwa example</title>
</Head>
<h1>Next.js + PWA = AWESOME!!</h1>
</>
);
return <></>;
}
6 changes: 3 additions & 3 deletions examples/lifecycle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.5.1",
"@types/react": "18.2.20",
"@types/node": "20.6.1",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"typescript": "5.1.6"
"typescript": "5.2.2"
}
}
3 changes: 3 additions & 0 deletions examples/lifecycle/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { AppProps } from "next/app";
import Head from "next/head";

import { PWALifeCycle } from "../components/PWALifecycle";

const APP_NAME = "next-pwa example";
const APP_DESCRIPTION = "This is an example of using next-pwa";

Expand All @@ -25,6 +27,7 @@ export default function App({ Component, pageProps }: AppProps) {
<link rel="manifest" href="/manifest.json" />
<link rel="shortcut icon" href="/favicon.ico" />
</Head>
<PWALifeCycle />
<Component {...pageProps} />
</>
);
Expand Down
12 changes: 12 additions & 0 deletions examples/lifecycle/pages/pages-router/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Head from "next/head";

export default function Index() {
return (
<>
<Head>
<title>next-pwa example</title>
</Head>
<h1>Next.js + PWA = AWESOME!!</h1>
</>
);
}
26 changes: 22 additions & 4 deletions examples/lifecycle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -14,8 +18,22 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"types": ["@ducanh2912/next-pwa/workbox"]
"types": [
"@ducanh2912/next-pwa/workbox"
],
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
Loading

0 comments on commit 12a6542

Please sign in to comment.