diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..753214e --- /dev/null +++ b/index.d.ts @@ -0,0 +1,19 @@ +import { Compiler, WebpackPluginInstance } from 'webpack'; +import { } from 'html-webpack-plugin'; + +declare module 'html-webpack-plugin' { + export interface Options extends InjectorOptions { } +} + +export interface InjectorOptions { + chunksConfig?: { + async?: string[], + defer?: string[], + removeDefer?: string[], + } +} + +export default class HtmlWebpackInjectorPlugin implements WebpackPluginInstance { + [index: string]: any; + apply: (compiler: Compiler) => void; +} \ No newline at end of file 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}); + }) + } + }); + } } }