Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoveDefer & typescript #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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});
})
}
});
}
}
}

Expand Down