[英]How to create a Cordova and TypeScript project by cmd
I use Cordova to develop a mobile application, and I type cordova create MyApp
in command-line to create a Cordova project. 我使用Cordova开发移动应用程序,并在命令行中键入
cordova create MyApp
来创建Cordova项目。
I can use JavaScript but I need use the TypeScript in my project. 我可以使用JavaScript,但是我需要在项目中使用TypeScript。
Please help me to create a Cordova project, powered by TypeScript without Visual Studio, or help me to add TypeScript to my Cordova project. 请帮助我创建一个由TypeScript支持而不使用Visual Studio的Cordova项目,或者帮助我将TypeScript添加到我的Cordova项目中。
Thank you so much. 非常感谢。
In essence (without getting into code and asset bundling) what you'll want to do is to 本质上 (无需考虑代码和资产捆绑),您要做的就是
index.ts
and then compile with output to ...\\MyApp\\www\\js\\index.js
, index.ts
编写“ TypeScript”代码,然后将输出编译到...\\MyApp\\www\\js\\index.js
, where MyApp
is your Cordova app folder and index.js
is the one referenced in your app's index.html
( <script type="text/javascript" src="js/index.js"></script>
). 其中
MyApp
是您的Cordova应用程序文件夹, index.js
是您应用程序的index.html
( <script type="text/javascript" src="js/index.js"></script>
)中引用的文件夹。
npm install -g typescript
To see if TypeScript is installed, type tsc -v
. 要查看是否已安装TypeScript,请键入
tsc -v
。 This should print a version number, so you'll see something like Version 2.7.2
. 这应该打印一个版本号,因此您将看到类似
Version 2.7.2
。
next copy index.js
to index.ts
so your \\js\\
folder will contain both files 接下来将
index.js
复制到index.ts
这样您的\\js\\
文件夹将同时包含两个文件
after you edit and save your TypeScript code in index.ts
, use "Command Prompt" or "Terminal", change directory to the \\js\\
folder, then run tsc index.ts
(this will compile index.ts
and update index.js
) 在将TypeScript代码编辑并保存到
index.ts
,使用“命令提示符”或“终端”,将目录更改为\\js\\
文件夹,然后运行tsc index.ts
(这将编译index.ts
并更新index.js
)
Note: when building your Cordova app, you will not need the source .ts file 注意:在构建Cordova应用时,您不需要源.ts文件
This is a manual process (you'll have to do it every time you change your code), but I think it will get you started and it gives you an understanding of what is going on before you move to bundling, etc... 这是一个手动过程(每次更改代码时都必须这样做),但是我认为它可以帮助您入门,并且可以让您在进行捆绑等之前了解正在发生的事情。
Next steps to take into account: 接下来要考虑的步骤:
dist
folder so you have clear separation of source files dist
文件夹,以便您清楚地分离源文件 tsconfig.json
tsconfig.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.