From 42bf554e91f4f1cdb46158da9f41126a5107662b Mon Sep 17 00:00:00 2001 From: tech-meppem Date: Mon, 23 Jan 2023 14:16:10 +0000 Subject: [PATCH 1/3] Remove defer attributes options --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.js b/index.js index 70ec8ce..b6d209c 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,7 @@ function handleChunksConfig(data, tags) { if (data.plugin.options.chunksConfig) { const asyncNames = data.plugin.options.chunksConfig.async; const deferNames = data.plugin.options.chunksConfig.defer; + const removeDeferNames = data.plugin.options.chunksConfig.removeDefer; if(asyncNames && typeof asyncNames === "object" && asyncNames.length){ tags.forEach(tag => { @@ -50,6 +51,17 @@ function handleChunksConfig(data, tags) { } }); } + + if(removeDeferNames && typeof removeDeferNames === "object" && removeDeferNames.length){ + tags.forEach(tag => { + // add defer only on script tags. + if (!tag.attributes.href && tag.attributes.src) { + removeDeferNames.forEach(name => { + addAttributesToTag(tag, name, {defer: false}); + }) + } + }); + } } } From c35ffc22d223e3d2064002842839556364ff282f Mon Sep 17 00:00:00 2001 From: tech-meppem Date: Mon, 23 Jan 2023 14:27:03 +0000 Subject: [PATCH 2/3] Added d.ts file --- index.d.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..52856fb --- /dev/null +++ b/index.d.ts @@ -0,0 +1,17 @@ +import { type WebpackPluginInstance } from 'webpack'; + +declare module "html-webpack-plugin" { + declare namespace HtmlWebpackPlugin { + interface Options { + chunksConfig: { + async: string[], + defer: string[], + removeDefer: string[], + } + } + } +} + +class HtmlWebpackInjectorPlugin implements WebpackPluginInstance { } + +module.exports = HtmlWebpackInjectorPlugin; From f716e496e95077e37d01e9a48ec4f8b5578a9d25 Mon Sep 17 00:00:00 2001 From: tech-meppem Date: Mon, 23 Jan 2023 14:59:49 +0000 Subject: [PATCH 3/3] fixed & improved d.ts file --- index.d.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/index.d.ts b/index.d.ts index 52856fb..753214e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,17 +1,19 @@ -import { type WebpackPluginInstance } from 'webpack'; +import { Compiler, WebpackPluginInstance } from 'webpack'; +import { } from 'html-webpack-plugin'; -declare module "html-webpack-plugin" { - declare namespace HtmlWebpackPlugin { - interface Options { - chunksConfig: { - async: string[], - defer: string[], - removeDefer: string[], - } - } - } +declare module 'html-webpack-plugin' { + export interface Options extends InjectorOptions { } } -class HtmlWebpackInjectorPlugin implements WebpackPluginInstance { } +export interface InjectorOptions { + chunksConfig?: { + async?: string[], + defer?: string[], + removeDefer?: string[], + } +} -module.exports = HtmlWebpackInjectorPlugin; +export default class HtmlWebpackInjectorPlugin implements WebpackPluginInstance { + [index: string]: any; + apply: (compiler: Compiler) => void; +} \ No newline at end of file