architgarg / html-webpack-injector

Plugin that simplifies injection of chunks into head and body using HtmlWebpackPlugin (with ability to provide async/defer)
29 stars 11 forks source link

RemoveDefer & typescript #13

Open tech-meppem opened 1 year ago

tech-meppem commented 1 year ago

I added an option called 'removeDefer' which removes the defer tag. This is useful if you set the scriptLoading: 'defer', option on the HtmlWebpackPlugin, as this way, you can have:

new HtmlWebpackPlugin({
    // Defer script loading for faster loading
    scriptLoading: 'defer',
    chunksConfig: {
        async: ["MyAsyncEntry"],
        removeDefer: ["MyAsyncEntry"],
    },
}),

And then MyAsyncEntry will only have async="async" as an attribute, and no longer will have defer="defer" as well.

I also added a typescript d.ts file, which augments the HtmlWebpackPlugin options to provide the types. Useful if you have your webpack files in typescript (like I do).