You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guides/webpack-and-typescript.md
+38-55Lines changed: 38 additions & 55 deletions
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,28 @@
1
1
---
2
-
title: Webpack & Typescript
2
+
title: Webpack 和 TypeScript
3
3
sort: 20
4
4
contributors:
5
5
- morsdyce
6
6
---
7
7
8
-
[TypeScript](https://www.typescriptlang.org)is a typed superset of JavaScript that compiles to plain JavaScript, in this guide we will learn how to integrate Typescript with webpack.
The tsconfig file can start as an empty configuration file, here you can see an example of a basic configuration for TypeScript to compile to es5 as well as providing support for JSX.
@@ -39,11 +38,12 @@ The tsconfig file can start as an empty configuration file, here you can see an
39
38
}
40
39
```
41
40
42
-
You can read more about tsconfig.json configuration options at the [TypeScript documentation website](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
A basic webpack with TypeScript config should look along these lines:
45
+
使用 TypeScript 编写的 webpack 基本配置大概是这样:
46
+
47
47
```js
48
48
module.exports= {
49
49
entry:'./index.ts',
@@ -65,28 +65,24 @@ module.exports = {
65
65
},
66
66
};
67
67
```
68
-
69
-
Here we specify our entry point to be __index.ts__ in our current directory,
70
-
an output file called __bundle.js__
71
-
and our TypeScript loader that is in charge of compiling our TypeScript file to JavaScript. We also add `resolve.extensions` to instruct webpack what file extensions to use when resolving Typescript modules.
In this guide we will be using ts-loader as currently it is easier enabling additional webpack features such as importing non code assets into your project.
First we add a new loader called source-map-loader.
132
124
133
-
To install it run:
125
+
首先我们添加一个新 loader,名为 source-map-loader,运行下面的命令安装:
126
+
`npm install --save-dev source-map-loader`。
134
127
135
-
`npm install --save-dev source-map-loader`.
136
-
137
-
Once the loader is installed we need to tell webpack we want to run this loader before any other loaders by using the `enforce: 'pre'` configuration flag.
138
-
Finally we need to enable source maps in webpack by specifying the `devtool` property.
139
-
Currently we use the 'inline-source-map' setting, to read more about this setting and see other options check out the [devtool documentation](https://webpack.js.org/configuration/devtool/).
This applies not only to svg but any custom loader you may want to use which includes css, scss, json or any other file you may wish to load in your project.
0 commit comments