From 7165f4db3c21bb796422fea60374b693cb2676a6 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 4 Sep 2021 16:48:08 -0500 Subject: [PATCH] Remove scripts from all pages --- nuxt.config.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nuxt.config.js b/nuxt.config.js index 90c7792..a36ab78 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -3,6 +3,8 @@ import { promises as fs } from 'fs' import pkg from './package' +const removeAllScripts = html => html.replace(/)<[^<]*)*<\/script>/gi, '') + export default { target: 'static', @@ -17,6 +19,14 @@ export default { * https://nuxtjs.org/api/configuration-hooks/ */ hooks: { + // This hook is called before generatic static html files for SPA mode + 'generate:page': (page) => { + page.html = removeAllScripts(page.html) + }, + // This hook is called before rendering the html to the browser + 'render:route': (url, page, { req, res }) => { + page.html = removeAllScripts(page.html) + } // build: { // before: storeAppLists // }, @@ -165,7 +175,7 @@ export default { // Always run - + // Push meta import rule for zip.js config.module.rules.push({ test: /\.js$/,