Hi, Your guide was very helpful. But I wounder how I can use jQuery now.
I'm just testing to add some script:
<br>
$(document).ready(function () {<br>
console.log("ready!");<br>
});<br>
On a contact page in script section but getting: Uncaught ReferenceError: $ is not defined
I know I should not put code like that but I'm working on a huge refactoring and there is a ton of such scripts everywhere.
Antwerp-based teacher at the Karel de Grote University of Applied Sciences and Arts. Avid programmer at the backend, frontend, and everything in between.
Location
Antwerp, Belgium
Work
Lecturer at KdG University of Applied Sciences and Arts
Hey, thanks for your comment! You won't be able to use jQuery in a script section using this setup. You can use jQuery in a JavaScript file that will be picked up by webpack, however.
If you do need jQuery in an inline JavaScript section, then I'd recommend adding reference to a jQuery CDN as well.
Hope this helps your refactoring. Good luck!!
Thank You for Your answer.
I did find another solution. I can use expose-loader to make it work.
{
test: require.resolve("jquery"),
loader: "expose-loader",
options: {
exposes: ["$", "jQuery"],
},
},
Antwerp-based teacher at the Karel de Grote University of Applied Sciences and Arts. Avid programmer at the backend, frontend, and everything in between.
Location
Antwerp, Belgium
Work
Lecturer at KdG University of Applied Sciences and Arts
Hi, Your guide was very helpful. But I wounder how I can use jQuery now.
I'm just testing to add some script:
<br> $(document).ready(function () {<br> console.log("ready!");<br> });<br>
On a contact page in script section but getting: Uncaught ReferenceError: $ is not defined
I know I should not put code like that but I'm working on a huge refactoring and there is a ton of such scripts everywhere.
Hey, thanks for your comment! You won't be able to use jQuery in a script section using this setup. You can use jQuery in a JavaScript file that will be picked up by webpack, however.
If you do need jQuery in an inline JavaScript section, then I'd recommend adding reference to a jQuery CDN as well.
Hope this helps your refactoring. Good luck!!
Thank You for Your answer.
I did find another solution. I can use expose-loader to make it work.
{
test: require.resolve("jquery"),
loader: "expose-loader",
options: {
exposes: ["$", "jQuery"],
},
},
Great! That looks like an ideal solution. Thanks for the addition!