全部的代码及笔记都可以在我的github上查看, 唤醒star: https://github.com/Jasonwang911/webpackStudyInit/tree/master/typescriptConfig
 

1. TS: js的超集 tslang.cn/typescriptlang.org
2. typesscript-loader 有两个
ts-loader 官方维护
awesome-typesctipt-loader 个人维护,运用了缓存,速度更快
3. 配置在 tsconfig.json 文件中
官网中: 官网/docs/handbook/compiler-options.html 查看相关具体配置
常用选项:
compilerOptions
include
exculde
4. 安装环境
sudo npm install typescript -g
npm install webpack typescript ts-loader awesome-typescript-loader --save-dev
在我安装依赖的时候出现 项目中 typesctipt 下载失败的情况,此时因为全局安装有 typescript ,可以直接链接过来,使用命令
npm link typescript
5. 配置webpack.config.js文件
module.exports = {
mode: 'development',
entry: {
'app': './src/app.ts'
},
output: {
filename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader'
}
}
]
},
devtool: 'source-map',
}
 
6. 配置tsconfig.json配置文件(注意json文件不可以写注释,请自行去掉注释)
{
"compilerOptions": {
// 包含es6 es7 和commonjs
"module": "commonjs",
// 目标运行环境
"target": "es5",
// 是不是允许 js语法
"allowJs": true,
},
"include": [
"./src/*"
],
"exclude": [
"./node_modules"
]
}
7. 使用第三方库的声明文件(校验第三方库文件的数据类型)
npm install @types/lodash
npm install @types/vue
。。。。
或者使用 Typings
a.全局安装 sodu npm install typings -g
b.使用typings 安装 typings install lodash --save 安装完成后会自动生成 typings.json 配置文件和 typings 文件夹
c.在tsconfig.json文件中添加 typeRoots 配置
 
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"allowJs": true,
"typeRoots": [
"./node_modules/@types",
"./typings/modules"
]
},
"include": [
"./src/*"
],
"exclude": [
"./node_modules"
]
}

  

webpack4 自学笔记二(typescript的配置)的更多相关文章

  1. redis相关笔记(二.集群配置及使用)

    redis笔记一 redis笔记二 redis笔记三 1.配置:在原redis-sentinel文件夹中添加{8337,8338,8339,8340}文件夹,且复制原8333中的配置 在上述8333配 ...

  2. webpack4 自学笔记一(babel的配置)

    所有代码都可以再我的github上查看,每个文件夹下都会有README.md,欢迎star: https://github.com/Jasonwang911/webpackStudyInit/tree ...

  3. webpack4 自学笔记三(提取公用代码)

    全部的代码及笔记都可以在我的github上查看, 欢迎star:https://github.com/Jasonwang911/webpackStudyInit/tree/master/commonT ...

  4. Spring4学习笔记二:Bean配置与注入相关

    一:Bean的配置形式 基于XML配置:在src目录下创建 applicationContext.xml  文件,在其中进行配置. 基于注解配置:在创建bean类时,通过注解来注入内容.(这个不好,因 ...

  5. webpack4 自学笔记四(style-loader)

    全部的代码及笔记都可以在我的github上查看, 欢迎star:https://github.com/Jasonwang911/webpackStudyInit/tree/master/css 引入- ...

  6. Webpack4 学习笔记六 多页面配置和devtool

    webpack 多页配置 webpack可以配置单页应用, 也可以配置多页应用. 区别在于, 单页应用entry入口只有一个, 而多页应用入口有多个 webpack配置: const path = r ...

  7. Webpack4 学习笔记二 CSS模块转换

    前言 此内容是个人学习笔记,以便日后翻阅.非教程,如有错误还请指出 webpack 打包css模块 webpack是js模块打包器, 如果在入口文件引入css文件或其它的less.sass等文件,需要 ...

  8. webpack4 自学笔记五(tree-shaking)

    全部的代码及笔记都可以在我的github上查看, 欢迎star: https://github.com/Jasonwang911/webpackStudyInit/tree/master/ThreeS ...

  9. Hadoop自学笔记(五)配置分布式Hadoop环境

    上一课讲了怎样在一台机器上建立Hadoop环境.我们仅仅配置了一个NHName Node, 这个Name Node里面包括了我们全部Hadoop的东西.包括Name Node, Secondary N ...

随机推荐

  1. express4.x socket

    在这个版本下使用socket,配置比较麻烦. 使用实例:http://www.open-open.com/lib/view/open1402479198587.html 配置文件:BarOrderPr ...

  2. android:theme

    附件:常用的系统提供的 android:theme 样式一览表 01 android:theme="@android:style/Theme.Dialog" 将一个Activity ...

  3. AngularJS transclude 理解及例子

    一.概念理解 transclude可以在指令中让使用者自定义模板,也就是说,指令中模板的一部分,让指令的使用者动态指定:与指定中的Scope属性值为{}时候的作用类似,scope属性让指令使用者动态制 ...

  4. spring boot thymeleaf

    引入支持 <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spr ...

  5. cxGrid动态设置单元格对齐方式

    cxGrid动态设置单元格对齐方式 2013年10月08日 00:52:49 踏雪无痕 阅读数:2150更多 个人分类: cxGrid   判断: //uses cxTextEditcxGrid1DB ...

  6. yum安装jdk如何配置JAVA_HOME

    安装Java环境 yum -y install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 查看安装后的配置 java -ver ...

  7. [leetcode.com]算法题目 - Gray Code

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  8. Android Dagger 2 无法自动生成 Dagger Component

    给项目升级 gradle(3.0)和 build(27)后发现 Dagger 2 无法自动生成 Dagger Component 类了. 原因竟是我把 : kapt 'com.google.dagge ...

  9. “全栈2019”Java多线程第三十四章:超时自动唤醒被等待的线程

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  10. 利用koa实现mongodb数据库的增删改查

    概述 使用koa免不了要操纵数据库,现阶段流行的数据库是mongoDB,所以我研究了一下koa里面mongoDB数据库的增删改查,记录下来,供以后开发时参考,相信对其他人也有用. 源代码请看:我的gi ...