当前位置:网站首页>01 Encounter typescript, build environment
01 Encounter typescript, build environment
2022-07-31 15:12:00 【It's a cloud!】
The typescript code we write will eventually be compiled into javascript code to run, so we need to build the corresponding environment
npm install typescript globally
npm install typescript -gView Version
tsc --versionWrite the first ts file

Running this ts file directly at this time is an error, we need to convert it to a js file, through the tsc we just installed
// Enter tsc in the console to add your filetsc .\01_hello-typescript.tsAt this point, you will find that there is one more file in your directory, this js file is the converted file

It's too troublesome to deal with ts code in this way, there are two solutions at present
Option 1: Build a webpack environment
Option 2: Install ts-node, ts-node helps us do two things, compile and run in the node environment
Here, use ts-node in the learning stage first
npm install ts-node -g// ts-node also depends on two other packages, which we also need to install globallynpm install tslib @types/node -gRun ts files through ts-node,
![]()
webpack builds ts environment (skipable)
This is my initial directory. After creating main.ts util.ts, after npm init, keep pressing Enter to create the package.json file

Partially install webpack webpack-cli
npm install webpack webpack-cli -DConfigure the build command in package.json first,

Create index.html in the root directory (template for creating local services)! After generating the template, it is OK
Then create the webpack.config.js file
const path = require("path");const HtmlWebpackPlugin = require("html-webpack-plugin");module.exports = {mode: "development",entry: "./src/main.ts",output: {path: path.resolve(__dirname, "./dist"),filename: "bundle.js",},resolve: {extensions: [".ts", ".js", ".json", ".cjs"],},devServer: {},module: {rules: [{test: /\.ts$/,loader: "ts-loader",},],},plugins: [new HtmlWebpackPlugin({template: "./index.html",}),],};The following are various installations, at the command line
// ts-loader depends on typescriptnpm install ts-loader typescript -D// The tsconfig.json file is required, here we generate it automaticallytsc --init// You can package it here, refer to the packaged file// debugging trouble, we start the local servicenpm install webpack-dev-server -D// specify the template herenpm install html-webpack-plugin -DSet the serve script

npm run serveIt's ok
边栏推荐
- The paper manual becomes 3D animation in seconds, the latest research of Wu Jiajun of Stanford University, selected for ECCV 2022
- AVH Deployment Practice (1) | Deploying the Flying Paddle Model on Arm Virtual Hardware
- 基于最小二乘法和SVM从天气预报中预测太阳能发电量(Matlab代码实现)
- 国内市场上的BI软件,到底有啥区别
- 四象限时间管理有多好用?
- Linux查看redis版本(查看mongodb版本)
- 如何进行需求分析评审
- 自适应控制——仿真实验三 用超稳定性理论设计模型参考自适应系统
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(caption、添加、修改可视化图像的题注、脚注内容)
- 01 邂逅typescript,环境搭建
猜你喜欢

最小费用最大流问题详解

DBeaver连接MySQL 8.x时Public Key Retrieval is not allowed 错误解决

Essential Learning for Getting Started with Unity Shader - Transparency Effect

网银被盗?这篇文章告诉你如何安全使用网银

Female service community product design

模板与泛型编程值typelist实现

LeetCode二叉树系列——110.平衡二叉树

Word table to Excel

【MySQL】Mysql范式及外键作用

Word表格转到Excel中
随机推荐
TRACE32——C源码关联
消息队列消息数据存储MySQL表设计
DBeaver连接MySQL 8.x时Public Key Retrieval is not allowed 错误解决
Word表格转到Excel中
OpenCV测量物体的尺寸技能 get~
数据库的范式(第一范式,第二范式,第三范式,BCNF范式)「建议收藏」
Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
R语言向前或者向后移动时间序列数据(自定义滞后或者超前的期数):使用dplyr包中的lag函数将时间序列数据向前移动一天(设置参数n为正值)
2021 OWASP TOP 10 漏洞指南
安装Xshell并使用其进行Ymodem协议的串口传输
R language ggplot2 visualization: use the ggboxplot function of the ggpubr package to visualize the grouped box plot, use the ggpar function to change the graphical parameters (caption, add, modify th
最小费用最大流问题详解
思路迪医药冲刺港股:5个月亏2.9亿 泰格医药与先声药业是股东
蔚来杯2022牛客暑期多校训练营4
Advanced Mathematics - Commonly Used Indefinite Integral Formulas
【CUDA学习笔记】初识CUDA
做事软件开发-法的重要性所在以及合理结论的认识
易驱线主控芯片对比(电动三轮电机90O瓦世纪通达)
Prometheus之node_exporter性能监控信息采集含义
[CUDA study notes] First acquaintance with CUDA