node.js - 运行空白打字稿项目
问题描述
我想运行一个带有 package.json、typescript 和 html 文件的空白 typescript 项目。-类似于 Stackblitz blank-typescript项目。任何人都可以为我提供一步一步的指导,如何设置这样的项目。如果知道这一点很重要,我目前正在使用 Webstorm 作为 IDE。
先感谢您!
解决方案
我想我有我的解决方案。
步骤1
在您的项目上安装打字稿npm install typescript --save
第2步
创建一个 tsconfig 文件来为您的项目应用打字稿规则tsc --init
第 3 步
创建 index.ts 和 index.html 文件 HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Promises vs. Observables</title>
</head>
<body>
<div id="app">
<script src="index.js"></script>
</div>
</body>
</html>
索引.ts:
const world = '️';
const appDiv: HTMLElement | null = document.getElementById('app');
if (appDiv) {
appDiv.innerHTML = `<h1>Hello ${world}</h1>`;
console.log(`hello ${world}`);
}
最后一步
在监视模式下编译tsc -w
项目正在运行!如果我可以在我的解决方案上做得更好,请不要犹豫告诉我!
推荐阅读
- c++ - 如何使用 msbuild 和设置 C++17 命令行编译 Visual Studio 项目?
- .net - 无法将 NuGet 包添加到 Dynamics 365 解决方案
- python - 将值列表读入 Python 变量(或变量)
- mysql - 转换 MySQL 表
- angular - 角度返回 url 为空
- reactjs - useEffect 中的 debounce 问题
- c++ - 从源代码构建 bcrypt,逐步使用 make
- tensorflow - Keras 模型不学习和预测三类中的一类
- xml - XML 输出是复制记录 VB.NET
- java - 使用终端时出现“发生 JNI 错误,请检查您的安装并重试”