Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack 5 adds defer="defer" to script tags?

my html document's head tag has in it:

<script src="/packs/vendors-node_modules_jquery_dist_jquery_js-exposed-e9b29cc0e77d15c93346.js" defer="defer"></script>

and in the document's body, I have a script tag which is trying to use jQuery, but I get the error that $ is undefined.

How can I make it so that expose-loader does not put that defer tag on jQuery so that it's available when my script tag is executed?

like image 333
patrick Avatar asked Oct 16 '25 20:10

patrick


1 Answers

I faced the same problem and finally solved it by installing html-webpack-plugin and adding a custom-webpack.config.js file with the following configuration:

new HtmlWebpackPlugin({
  ...
  scriptLoading: 'blocking',
}),

This config removed the defer="defer" from my scripts.

like image 55
kikus Avatar answered Oct 18 '25 18:10

kikus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!