[英]How to install and run typescript jquery / bootstrap definition file locally using npm typings?
What I am trying to do, installing typescript jquery and boostrap definition file in my new project using npm typings. 我要做什么,使用npm类型在我的新项目中安装打字稿jquery和boostrap定义文件。
Below is the steps which I followed. 以下是我遵循的步骤。
1- open cmd and goto my currrent project folder and type following commands. 1-打开cmd并转到我的当前项目文件夹,然后键入以下命令。
npm install typings --global npm安装类型--global
typings init 类型初始化
typings install dt~jquery --global --save 键入install dt〜jquery --global --save
typings install dt~boostrap --global --save 键入install dt〜boostrap --global --save
2- below is my tsconfig file configuration { "compilerOptions": { "target": "es5", "module": "commonjs", "sourceMap": true, "rootDir": "./TS", "outDir": "./JS", "watch": true } }
2-下面是我的tsconfig文件配置{ "compilerOptions": { "target": "es5", "module": "commonjs", "sourceMap": true, "rootDir": "./TS", "outDir": "./JS", "watch": true } }
Note: I created separate folder for TS file and JS file. 注意:我为TS文件和JS文件创建了单独的文件夹。 So when typescript transpile, it create javascript file in JS directory. 因此,当打字稿转换时,它将在JS目录中创建javascript文件。
3- Add document.ready
function in ts file and write alert when page load 3-在ts文件中添加document.ready
函数并在页面加载时写警报
4- Build and run index.html file 4-构建并运行index.html文件
Note: I add transpile javascript in head section so there is no need to mention here any code. 注意:我在开头部分添加了可转换的javascript,因此这里无需提及任何代码。
Error: In browser console window its shows me below error: 错误:在浏览器控制台窗口中,它向我显示以下错误:
myscript.ts:2 Uncaught ReferenceError: $ is not defined myscript.ts:2未捕获的ReferenceError:未定义$
Here is my repository . 这是我的资料库 。
Please help me here. 请在这里帮助我。 What I am doing wrong to installing jquery in my project. 我在我的项目中安装jquery时做错了什么。
As far as I can see from your rep - you have forgot to load the actual bootstrap and jquery in your page. 据我从您的代表处看到的-您忘记了在页面中加载实际的引导程序和jquery。 The typescript definitions only provide compiletime information for the typescript transpiler about content of thouse libraries. 打字稿定义仅为打字稿编译器提供有关thouse库内容的编译时信息。 The libraries them self must be loaded in your index.html
. 它们本身的库必须加载到index.html
。 You can do it in two ways: 您可以通过两种方式进行操作:
Hope this will help you to get started. 希望这会帮助您入门。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.