当前位置:网站首页>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 -g
View Version
tsc --version
Write 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.ts
At 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 -g
Run 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 -D
Configure 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 -D
Set the serve script
npm run serve
It's ok
边栏推荐
- 分成两栏后文字顺序混乱的问题解决【写期刊论文时】
- R语言计算时间序列数据的移动平均值(滚动平均值、例如5日均线、10日均线等):使用zoo包中的rollmean函数计算k个周期移动平均值
- hough变换检测直线原理(opencv霍夫直线检测)
- Recommendation System - Recall Phase - 2013: DSSM (Twin Towers Model) [Embedding (Semantic Vector) Recall] [Microsoft]
- 模板与泛型编程值typelist实现
- TRACE32——基于SNOOPer的变量记录
- AVH部署实践 (一) | 在Arm虚拟硬件上部署飞桨模型
- Destruction order of thread_local variables
- Node实现数据加密
- [CUDA study notes] First acquaintance with CUDA
猜你喜欢
随机推荐
架构实战营模块8消息队列表结构设计
Trigonometric identity transformation formula
DeepLab系列学习
Nuget打包并上传教程
SIGABRT 报错时的注意事项和解决方法
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
The meaning of node_exporter performance monitoring information collection in Prometheus
小试牛刀:Go 反射帮我把 Excel 转成 Struct
Emmet 语法
border控件的使用
2021 OWASP TOP 10 Vulnerability Guide
「秋招系列」MySQL面试核心25问(附答案)
NC | 中国农大草业学院杨高文组揭示发现多因子干扰会降低土壤微生物多样性的积极效应...
DBeaver连接MySQL 8.x时Public Key Retrieval is not allowed 错误解决
vb中如何连接mysql_vb怎么连接数据库「建议收藏」
国内市场上的BI软件,到底有啥区别
华医网冲刺港股:5个月亏2976万 红杉与姚文彬是股东
TRACE32 - SNOOPer-based variable logging
abaqus find contact pairs报错:surface name is already in use
模板与泛型编程值typelist实现