Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
feat: rename pwa plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jun 3, 2022
1 parent e861b23 commit 1d341c3
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 98 deletions.
2 changes: 1 addition & 1 deletion docs/pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pwa-docs",
"version": "1.30.0",
"private": true,
"description": "Docs for @mr-hope/vuepress-plugin-pwa",
"description": "Docs for vuepress-plugin-pwa1",
"license": "MIT",
"author": {
"name": "Mr.Hope",
Expand Down
2 changes: 1 addition & 1 deletion docs/pwa/src/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default hope.config({
color: "#ffffff",
},
manifest: {
name: "@mr-hope/vuepress-plugin-pwa",
name: "vuepress-plugin-pwa1",
short_name: "pwa plugin",
icons: [
{
Expand Down
10 changes: 5 additions & 5 deletions docs/pwa/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ home: true
title: Home
icon: home
heroImage: /logo.svg
heroText: "@mr-hope/vuepress-plugin-pwa"
heroText: "vuepress-plugin-pwa1"
tagline: A powerfull PWA plugin
action:
- text: Guide 💡
Expand All @@ -28,15 +28,15 @@ This plugin will turn on Progressive Web App Support.
::: code-group-item yarn

```bash
yarn add -D @mr-hope/vuepress-plugin-pwa
yarn add -D vuepress-plugin-pwa1
```

:::

::: code-group-item npm

```bash
npm i -D @mr-hope/vuepress-plugin-pwa
npm i -D vuepress-plugin-pwa1
```

:::
Expand All @@ -54,7 +54,7 @@ npm i -D @mr-hope/vuepress-plugin-pwa
export default {
plugins: [
[
"@mr-hope/pwa",
"pwa1",
{
// your options
},
Expand All @@ -72,7 +72,7 @@ export default {
module.exports = {
plugins: [
[
"@mr-hope/pwa",
"pwa1",
{
// your options
},
Expand Down
10 changes: 5 additions & 5 deletions docs/pwa/src/zh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ home: true
title: 主页
icon: home
heroImage: /logo.svg
heroText: "@mr-hope/vuepress-plugin-pwa"
heroText: "vuepress-plugin-pwa1"
tagline: 一个强大的 PWA 插件
action:
- text: 快速上手 💡
Expand All @@ -28,15 +28,15 @@ copyrightText: false
::: code-group-item yarn

```bash
yarn add -D @mr-hope/vuepress-plugin-pwa
yarn add -D vuepress-plugin-pwa1
```

:::

::: code-group-item npm

```bash
npm i -D @mr-hope/vuepress-plugin-pwa
npm i -D vuepress-plugin-pwa1
```

:::
Expand All @@ -54,7 +54,7 @@ npm i -D @mr-hope/vuepress-plugin-pwa
export default {
plugins: [
[
"@mr-hope/pwa",
"pwa1",
{
// 配置选项
},
Expand All @@ -72,7 +72,7 @@ export default {
module.exports = {
plugins: [
[
"@mr-hope/pwa",
"pwa1",
{
// 你的选项
},
Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/config/plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tags:

- [@mr-hope/vuepress-plugin-git][git]: Info plugin based on git

- [@mr-hope/vuepress-plugin-pwa][pwa]: Powerful PWA support
- [vuepress-plugin-pwa1][pwa]: Powerful PWA support

- [vuepress-plugin-reading-time1][reading-time]: Expect reading time and words count

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ The theme also includes the following plugins, you can use them in other themes

- [@mr-hope/vuepress-plugin-git][git]: Info plugin based on git

- [@mr-hope/vuepress-plugin-pwa][pwa]: PWA support
- [vuepress-plugin-pwa1][pwa]: PWA support

- [vuepress-plugin-reading-time1][reading-time]: Expect reading time and words count

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/guide/feature/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The theme includes the following plugins, you can use them directly in other the

- [@mr-hope/vuepress-plugin-git][git]: Info based on git

- [@mr-hope/vuepress-plugin-pwa][pwa]: PWA support
- [vuepress-plugin-pwa1][pwa]: PWA support

- [vuepress-plugin-reading-time1][reading-time]: Expect reading time and words count

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/guide/feature/pwa.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:
- pwa
---

The theme will enable progressive web app support[^pwa-intro] by including [`@mr-hope/vuepress-plugin-pwa`](https://vuepress-theme-hope.github.io/v1/pwa/).
The theme will enable progressive web app support[^pwa-intro] by including [`vuepress-plugin-pwa1`](https://vuepress-theme-hope.github.io/v1/pwa/).

[^pwa-intro]: **PWA introduction**

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/zh/config/plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tags:

- [@mr-hope/vuepress-plugin-git][git]: 基于 Git 的页面信息插件

- [@mr-hope/vuepress-plugin-pwa][pwa]: PWA 支持
- [vuepress-plugin-pwa1][pwa]: PWA 支持

- [vuepress-plugin-reading-time1][reading-time]: 阅读时间与字数统计

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/zh/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ tags:

- [@mr-hope/vuepress-plugin-git][git]: 基于 Git 的页面信息插件

- [@mr-hope/vuepress-plugin-pwa][pwa]: PWA 支持
- [vuepress-plugin-pwa1][pwa]: PWA 支持

- [vuepress-plugin-reading-time1][reading-time]: 阅读时间与字数统计

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/zh/guide/feature/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tags:

- [@mr-hope/vuepress-plugin-git][git]: 基于 Git 的页面信息插件

- [@mr-hope/vuepress-plugin-pwa][pwa]: PWA 支持
- [vuepress-plugin-pwa1][pwa]: PWA 支持

- [vuepress-plugin-reading-time1][reading-time]: 阅读时间与字数统计

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/zh/guide/feature/pwa.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:
- pwa
---

默认情况下,该主题将通过内置 [`@mr-hope/vuepress-plugin-pwa`](https://vuepress-theme-hope.github.io/v1/pwa/zh/) 启用渐进式 Web 应用程序支持[^pwa-intro]
默认情况下,该主题将通过内置 [`vuepress-plugin-pwa1`](https://vuepress-theme-hope.github.io/v1/pwa/zh/) 启用渐进式 Web 应用程序支持[^pwa-intro]

如果你不需要此功能或想使用其他 pwa 插件,则可以将 `themeConfig.pwa` 设置为 `false` 来禁用该插件。

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@commitlint/config-conventional": "17.0.2",
"@mr-hope/vuepress-plugin-components": "workspace:*",
"@mr-hope/vuepress-plugin-git": "workspace:*",
"@mr-hope/vuepress-plugin-pwa": "workspace:*",
"@mr-hope/vuepress-plugin-sitemap": "workspace:*",
"@mr-hope/vuepress-plugin-smooth-scroll": "workspace:*",
"@mr-hope/vuepress-theme-types": "workspace:*",
Expand Down Expand Up @@ -101,6 +100,7 @@
"vuepress-plugin-feed1": "workspace:*",
"vuepress-plugin-md-enhance": "workspace:*",
"vuepress-plugin-photo-swipe": "workspace:*",
"vuepress-plugin-pwa1": "workspace:*",
"vuepress-plugin-reading-time1": "workspace:*",
"vuepress-plugin-seo1": "workspace:*",
"vuepress-shared": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions packages/pwa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<p align="center">
<img width="240" src="https://vuepress-theme-hope.github.io/v1/logo.svg" style="text-align: center;"/>
</p>
<h1 align="center">@mr-hope/vuepress-plugin-pwa</h1>
<h1 align="center">vuepress-plugin-pwa1</h1>
<h4 align="center">VuePress PWA plugin📦 / VuePress PWA 插件📦</h4>

[![Version](https://img.shields.io/npm/v/@mr-hope/vuepress-plugin-pwa.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/@mr-hope/vuepress-plugin-pwa.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/@mr-hope/vuepress-plugin-pwa?style=flat-square&logo=npm)](https://www.npmjs.com/package/@mr-hope/vuepress-plugin-pwa)
[![Version](https://img.shields.io/npm/v/vuepress-plugin-pwa1.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/vuepress-plugin-pwa1.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/vuepress-plugin-pwa1?style=flat-square&logo=npm)](https://www.npmjs.com/package/vuepress-plugin-pwa1)

<!-- markdownlint-restore -->

Expand All @@ -22,11 +22,11 @@ VuePress 2 is recommanded to start new project. You should use [`vuepress-plugin
## Install / 安装

```bash
npm i -D @mr-hope/vuepress-plugin-pwa
npm i -D vuepress-plugin-pwa1
```

Or

```bash
yarn add -D @mr-hope/vuepress-plugin-pwa
yarn add -D vuepress-plugin-pwa1
```
2 changes: 1 addition & 1 deletion packages/pwa/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@mr-hope/vuepress-plugin-pwa",
"name": "vuepress-plugin-pwa1",
"version": "1.30.0",
"description": "Powerful PWA plugin for vuepress",
"keywords": [
Expand Down
27 changes: 11 additions & 16 deletions packages/pwa/src/node/generateManifest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { getRootLang } from "vuepress-shared";
import { black, blue, cyan } from "chalk";
import { cyan } from "chalk";
import { existsSync, readFile, writeJSON } from "fs-extra";
import { relative, resolve } from "path";
import { getRootLang } from "vuepress-shared";

import { logger } from "./utils";

import type { Context } from "vuepress-typings";
import type { ManifestOption, PWAOptions } from "../types";
Expand All @@ -14,13 +16,12 @@ export const getManifest = async (
const { base, sourceDir, siteConfig } = context;
const userManifestPath = resolve(
sourceDir,
"./.vuepress/public/manifest.webmanifest"
".vuepress/public/manifest.webmanifest"
);
const userManifestJSONPath = resolve(
sourceDir,
"./.vuepress/public/manifest.json"
".vuepress/public/manifest.json"
);

const optionManifest = options.manifest || {};

const userManifest = JSON.parse(
Expand Down Expand Up @@ -56,25 +57,19 @@ export const getManifest = async (
};

export const generateManifest = async (
context: Context,
{ cwd, outDir }: Context,
manifest: Promise<ManifestOption>
): Promise<void> => {
console.log(
blue("PWA:"),
black.bgYellow("wait"),
"Generating manifest.webmanifest..."
);
logger.load("Generating manifest.webmanifest");

const { cwd, outDir } = context;
const manifestPath = resolve(outDir, "manifest.webmanifest");

await writeJSON(manifestPath, await manifest, {
flag: "w",
});

console.log(
blue("PWA:"),
black.bgGreen("Success"),
`Manifest generated and saved to ${cyan(relative(cwd, manifestPath))}`
logger.succeed();
logger.update(
`Manifest generated and saved to ${cyan(relative(cwd, manifestPath))}!`
);
};
59 changes: 24 additions & 35 deletions packages/pwa/src/node/generateServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { black, blue, cyan } from "chalk";
import { blue, cyan } from "chalk";
import { statSync } from "fs-extra";
import { resolve } from "path";
import { generateSW } from "workbox-build";
import { logger } from "./utils";

import type { Context } from "vuepress-typings";
import type {
ManifestEntry,
ManifestTransform,
ManifestTransformResult,
} from "workbox-build";

import type { Context } from "vuepress-typings";
import type { PWAOptions } from "../types";

const imageFilter =
Expand All @@ -35,16 +37,13 @@ const imageFilter =
};

export const generateServiceWorker = async (
context: Context,
{ outDir, siteConfig }: Context,
options: PWAOptions
): Promise<void> => {
console.log(
blue("PWA:"),
black.bgYellow("wait"),
"Generating service worker..."
);
const { title, locales = {} } = context.siteConfig;
const swDest = resolve(context.outDir, "./service-worker.js");
logger.load("Generating service worker");

const { title, locales = {} } = siteConfig;
const swDest = resolve(outDir, "./service-worker.js");

const globPatterns = ["**/*.{js,css,svg}", "**/*.{woff,woff2,eot,ttf,otf}"];

Expand All @@ -55,47 +54,37 @@ export const generateServiceWorker = async (

await generateSW({
swDest,
globDirectory: context.outDir,
globDirectory: outDir,
cacheId: title || locales["/"]?.title || "hope",
globPatterns,
cleanupOutdatedCaches: true,
clientsClaim: true,
maximumFileSizeToCacheInBytes: (options.maxSize || 2048) * 1024,
manifestTransforms: [imageFilter(context.outDir, options.maxPicSize)],
manifestTransforms: [imageFilter(outDir, options.maxPicSize)],
...(options.generateSWConfig || {}),
}).then(({ count, size, warnings }) => {
console.log(
blue("PWA:"),
black.bgGreen("Success"),
`Generated service worker, which will precache ${cyan(
`${count} files`
)}, totaling ${cyan(`${(size / 1024 / 1024).toFixed(2)} Mb`)}.`
logger.succeed();

logger.info(
`Precache ${cyan(`${count} files`)}, totaling ${cyan(
`${(size / 1024 / 1024).toFixed(2)} Mb.`
)}.`
);

if (warnings.length)
console.log(
blue("PWA:"),
black.bgYellow("Warning"),
`${warnings.map((warning) => ` · ${warning}`).join("\n")}`
);
logger.warn(`${warnings.map((warning) => ` · ${warning}`).join("\n")}`);

if (size > 104857600)
console.log(
blue("PWA:"),
black.bgRed("Error"),
"Cache Size is larger than 100MB, so that it can not be registerd on all browsers.\n",
blue(
logger.error(
`Cache Size is larger than 100MB, so that it can not be registerd on all browsers.\n${blue(
"Please consider disable `cacheHTML` and `cachePic`, or set `maxSize` and `maxPicSize` option.\n"
)
)}`
);
else if (size > 52428800)
console.log(
blue("PWA:"),
black.bgYellow("Warning"),
"\nCache Size is larger than 50MB, which will not be registerd on Safari.\n",
blue(
logger.warn(
`\nCache Size is larger than 50MB, which will not be registerd on Safari.\n${blue(
"Please consider disable `cacheHTML` and `cachePic`, or set `maxSize` and `maxPicSize` option.\n"
)
)}`
);
});
};
Loading

0 comments on commit 1d341c3

Please sign in to comment.