From d08fe29d970948cbf31811a7bced0adc2488d621 Mon Sep 17 00:00:00 2001 From: Tiny Date: Thu, 14 Apr 2022 14:29:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20add=20a=20config=20item=20to=20web?= =?UTF-8?q?=EF=BC=8Clet=20the=20developer=20can=20select=20whether=20enabl?= =?UTF-8?q?e=20the=20html=20cache=20(#3108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 为web添加cache配置项,用户可以自己决定是否启用Html缓存 * related to the change for https://github.com/verdaccio/verdaccio/pull/3108 * related to the change for https://github.com/verdaccio/verdaccio/pull/3108 * apply changes from 5.x branch Co-authored-by: fengdi Co-authored-by: Juan Picado --- .changeset/slow-carrots-relate.md | 6 ++++++ packages/config/src/conf/default.yaml | 1 + packages/config/src/conf/docker.yaml | 15 +++++++++++++++ packages/web/src/renderHTML.ts | 9 +++++++-- website/docs/web.md | 5 +++-- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 .changeset/slow-carrots-relate.md diff --git a/.changeset/slow-carrots-relate.md b/.changeset/slow-carrots-relate.md new file mode 100644 index 000000000..35f0bb6df --- /dev/null +++ b/.changeset/slow-carrots-relate.md @@ -0,0 +1,6 @@ +--- +'@verdaccio/config': minor +'@verdaccio/web': minor +--- + +feat(web): add a config item to web,let the developer can select whet……her enable the html cache diff --git a/packages/config/src/conf/default.yaml b/packages/config/src/conf/default.yaml index b23f8492f..3e3a1e9b8 100644 --- a/packages/config/src/conf/default.yaml +++ b/packages/config/src/conf/default.yaml @@ -19,6 +19,7 @@ web: # sort_packages: asc # convert your UI to the dark side # darkMode: true + # html_cache: true # HTML tags injected after manifest # scriptsBodyAfter: # - '' diff --git a/packages/config/src/conf/docker.yaml b/packages/config/src/conf/docker.yaml index 1c885eb3a..50efdde78 100644 --- a/packages/config/src/conf/docker.yaml +++ b/packages/config/src/conf/docker.yaml @@ -23,7 +23,22 @@ web: # gravatar: false # by default packages are ordercer ascendant (asc|desc) # sort_packages: asc + # convert your UI to the dark side # darkMode: true + # html_cache: true + # HTML tags injected after manifest + # scriptsBodyAfter: + # - '' + # HTML tags injected before ends + # metaScripts: + # - '' + # - '' + # - '' + # HTML tags injected first child at + # bodyBefore: + # - '
html before webpack scripts
' + # Public path for template manifest scripts (only manifest) + # publicPath: http://somedomain.org/ # translate your registry, api i18n not available yet # i18n: diff --git a/packages/web/src/renderHTML.ts b/packages/web/src/renderHTML.ts index 808446fdf..975195f80 100644 --- a/packages/web/src/renderHTML.ts +++ b/packages/web/src/renderHTML.ts @@ -26,6 +26,9 @@ export default function renderHTML(config, manifest, manifestFiles, req, res) { const base = getPublicUrl(config?.url_prefix, req); const basename = new URL(base).pathname; const language = config?.i18n?.web ?? DEFAULT_LANGUAGE; + const needHtmlCache = [undefined, null].includes(config?.web?.html_cache) + ? true + : config.web.html_cache; const darkMode = config?.web?.darkMode ?? false; const title = config?.web?.title ?? WEB_TITLE; const login = hasLogin(config); @@ -81,8 +84,10 @@ export default function renderHTML(config, manifest, manifestFiles, req, res) { manifest ); debug('template :: %o', webPage); - cache.set('template', webPage); - debug('set template cache'); + if (needHtmlCache) { + cache.set('template', webPage); + debug('set template cache'); + } } else { debug('reuse template cache'); } diff --git a/website/docs/web.md b/website/docs/web.md index afe8cb5ec..40ffd2ab8 100644 --- a/website/docs/web.md +++ b/website/docs/web.md @@ -33,7 +33,8 @@ web: - '' - '' scriptsbodyBefore: - - '
html before webpack scripts
' + - '
html before webpack scripts
' + html_cache: true ``` All access restrictions defined to [protect your packages](protect-your-dependencies.md) will also apply to the Web Interface. @@ -73,7 +74,7 @@ i18n: | scriptsBodyAfter | string[] | No | any list of strings | `>=5.0.0` | inject scripts after the tag | | metaScripts | string[] | No | any list of strings | `>=5.0.0` | inject scripts inside | | scriptsbodyBefore | string[] | No | any list of strings | `>=5.0.0` | inject scripts before the | - +| html_cache | boolean | No | true | `>=v5.9.0` | whether the html cache is enabled, default true | > The recommended logo size is `40x40` pixels.