当前位置:网站首页>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
边栏推荐
- 定时器的类型
- Matlab矩阵基本操作(定义,运算)
- element-plus虚拟表格virtual-list组件中是怎么实现清理lodash.memoize缓存的?
- The R language ggstatsplot package ggbarstats function visualizes bar charts, and adds hypothesis test results (including sample number, statistics, effect size and its confidence interval, significan
- Gorm—Go语言数据库框架
- Prometheus之node_exporter性能监控信息采集含义
- 力扣:56. 合并区间
- Word table to Excel
- 公告
- Essential Learning for Getting Started with Unity Shader - Transparency Effect
猜你喜欢
随机推荐
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、使用font函数自定义图例标题文本(legend.title)字体的大小、颜色、样式(粗体、斜体)
NC | 斯坦福申小涛等开发数据可重复分析计算框架TidyMass
Nuget打包并上传教程
架构实战营模块8消息队列表结构设计
消息队列消息数据存储MySQL表设计
Message queue data storage MySQL table design
小试牛刀:Go 反射帮我把 Excel 转成 Struct
RecyclerView高效使用第二节
Essential Learning for Getting Started with Unity Shader - Transparency Effect
【CUDA学习笔记】初识CUDA
Ubantu专题5:设置静态ip地址
R language moves time series data forward or backward (custom lag or lead period): use the lag function in the dplyr package to move the time series data forward by one day (set the parameter n to a p
力扣:738.单调递增的数字
LeetCode二叉树系列——222.完全二叉树的节点个数
自适应控制——仿真实验二 用Narendra方案设计模型参考自适应系统
AVH Deployment Practice (1) | Deploying the Flying Paddle Model on Arm Virtual Hardware
element-plus虚拟表格virtual-list组件中是怎么实现清理lodash.memoize缓存的?
学习笔记12--路径-速度分解法之局部路径搜索
力扣:714. 买卖股票的最佳时机含手续费
Trigonometric identity transformation formula








