当前位置:网站首页>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
边栏推荐
猜你喜欢
WeChat chat record search in a red envelope
The paper manual becomes 3D animation in seconds, the latest research of Wu Jiajun of Stanford University, selected for ECCV 2022
button控件的使用
学习笔记12--路径-速度分解法之局部路径搜索
乡村基冲刺港交所:5个月期内亏2224万 SIG与红杉中国是股东
Getting started with UnityShader (3) - Unity's Shader
消息队列消息数据存储MySQL表设计
Female service community product design
模板与泛型编程值typelist实现
Ubuntu Topic 5: Setting a Static IP Address
随机推荐
网线RJ45接口针脚[通俗易懂]
R language test whether the sample conforms to normality (test whether the sample comes from a normally distributed population): shapiro.test function tests whether the sample conforms to the normal d
OpenShift 4 - 用 Operator 部署 Redis 集群
学习笔记12--路径-速度分解法之局部路径搜索
hough变换检测直线原理(opencv霍夫直线检测)
NPM Taobao mirror (latest version) released a new version of npm mirror at 2021-11-21 16:53:52 [easy to understand]
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、使用font函数自定义图例标题文本(legend.title)字体的大小、颜色、样式(粗体、斜体)
基于最小二乘法和SVM从天气预报中预测太阳能发电量(Matlab代码实现)
763.划分字母区间——之打开新世界
TRACE32——常用操作
《微信小程序-进阶篇》Lin-ui组件库源码分析-Icon组件
易驱线主控芯片对比(电动三轮电机90O瓦世纪通达)
模板与泛型编程值typelist实现
三、数组
thread_local 变量的析构顺序
Emmet 语法
Selenium自动化中无头浏览器的应用
OpenShift 4 - Deploy Redis Cluster with Operator
R语言检验样本是否符合正态性(检验样本是否来自一个正态分布总体):shapiro.test函数检验样本是否符合正态分布(normality test)
How to clean up the lodash.memoize cache in the element-plus virtual table virtual-list component?