The process of losing weight is one that requires dedication and hard work, and when you reach the goals it is necessary of you to ensure that you keep those pounds off. It is funny how individuals…
I’m assuming here that you’ve already read my blog for initializing webpack application, if you’ve not read it yet, I advise you to read it here https://medium.com/@shridharkaushik29/initializing-web-application-using-typescript-webpack-and-yarn-a8cecf13c9d4, before reading this post.
There are many Libraries which do not support ES6 import syntax, and exposes some global variables, such as jQuery exposes jQuery
& $
in global scope, AngularJS exposes angular
in global scope. Thus we need a loader which can evaluate the imported script file in the global scope, for this we’ll use script-loader
.
Installing Packages
For example, I’m showing how to use jQuery with typescript application.
You can see here, I’ve used “script-loader!” as prefix for the package name i.e. jquery. This tells the webpack to pass the imported script into script-loader before importing. Therefore, when the contents of the script are passed into the script loader, it evaluates them in the global scope of the browser.
Lets put some jQuery code in index.ts
, to see the magic of the script-loader
.
You’ll see the text inserted as HTML into the element having id demo-text
. Output will be something like this.
You can use any library or script which exposes global variables in browser’s global scope using this method.
Thanks for reading the post. Please applause and share if you liked the post. If you have any query or problem, please let me know in the comments.
Cheguei na beira do rio, finalmente, pés e mãos sangravam. Muito aquela montanha me machucou. Principalmente meu coração, quando minha amada não suportou as dificuldades da viagem e caiu. Naquele…
Brett Christensen Cheney Meaghan Dennett Tracy Aston Bart Elbey Irene Brooks Jenny Naiman Olson Anna West Molly Skeen Sundance Kid Whistling woods edh lamport Harper Thorpe Leah J Spence Jac Harmony…
Mech Master is a first-ever 3D Turn-based Mecha Blockchain game, with strategic RPG elements, where you can earn tokens through skillful gameplay and smart trading. Mech Master is not only an…