随笔 - 148  文章 - 0  评论 - 13  阅读 - 21万

ts配置

我们将使用 babel 去编译 TypeScript,babel 在编译 TypeScript 代码是直接去掉 TypeScript 的类型,然后当成普通的 javascript 代码使用各种插件进行编译,tsc 并没有介入编译过程,因此 tsconfig.json 中很多选项例如 target 和 module 是没有用的,可以让 VSCode 等编辑器正确提示错误
在项目中使用ts
yarn add typescript -D
// 新建 tsconfig.json 文件,进行ts 配置

通过babel来编译ts文件
yarn add babel-loader @babel/core @babel/preset-typescript -D
在babel.config.js 中配置
module.exports = function (api) {
api.cache(true);
const presets = ['@babel/preset-typescript'];
const plugins = [];
return { presets, plugins, };
};

在webpack 中配置 babel-loader
{
test: /.(tsx?|js)$/,
loader: 'babel-loader',
// 开启缓存
options: { cacheDirectory: true },
exclude: /node_modules/,
}

posted on   长安城下翩翩少年  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示