Skip to content

Commit 0a92370

Browse files
committed
Begin typescript-rework v2
1 parent b9f88c2 commit 0a92370

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

content/guides/typescript.md

+33-15
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,37 @@ contributors:
77
- mtrivera
88
---
99

10+
T> This guide stems from the [*Getting Started*](/guides/getting-started/) guide.
11+
1012
[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.
1113

1214

1315
## Basic Setup
1416

15-
In order to get started with webpack and TypeScript, first we must [install webpack](/guides/installation/) in our project.
16-
17-
To start using webpack with TypeScript you need a couple of things:
18-
19-
1. Install the TypeScript compiler in your project.
20-
2. Install a TypeScript loader (in this case we're using `ts-loader`).
21-
3. Create a __tsconfig.json__ file to contain our TypeScript compilation configuration.
22-
4. Create __webpack.config.js__ to contain our webpack configuration.
23-
24-
You can install the TypeScript compiler and loader by running:
17+
First install the TypeScript compiler and loader by running:
2518

2619
``` bash
2720
npm install --save-dev typescript ts-loader
2821
```
2922

23+
Now we'll modify the directory structure & the configuration files:
24+
25+
__project__git stat
26+
27+
``` diff
28+
webpack-demo
29+
|- package.json
30+
+ |- tsconfig.json
31+
|- webpack.config.js
32+
|- /dist
33+
|- bundle.js
34+
|- index.html
35+
|- /src
36+
|- index.js
37+
+ |- index.ts
38+
|- /node_modules
39+
```
40+
3041
__tsconfig.json__
3142

3243
Let's set up a simple configuration to support JSX and compile TypeScript down to ES5...
@@ -54,6 +65,8 @@ To learn more about webpack configuration, see the [configuration concepts](/con
5465
Now let's configure webpack to handle TypeScript:
5566

5667
```js
68+
const path = require('path');
69+
5770
module.exports = {
5871
entry: './index.ts',
5972
module: {
@@ -70,12 +83,12 @@ module.exports = {
7083
},
7184
output: {
7285
filename: 'bundle.js',
73-
path: __dirname
86+
path: path.resolve(__dirname, 'dist');
7487
}
7588
};
7689
```
7790

78-
This will direct webpack to _enter_ through `./index.ts`, _load_ all `.ts` and `.tsx` files through the `ts-loader`, and _output_ a `bundle.js` file in our current directory.
91+
This will direct webpackgit sdt to _enter_ through `./index.ts`, _load_ all `.ts` and `.tsx` files through the `ts-loader`, and _output_ a `bundle.js` file in our current directory.
7992

8093

8194
## Loader
@@ -138,8 +151,13 @@ declare module "*.svg" {
138151
Here we declare a new module for SVGs by specifying any import that ends in `.svg` and defining the module's `content` as `any`. We could be more explicit about it being a url by defining the type as string. The same concept applies to other assets including CSS, SCSS, JSON and more.
139152

140153

141-
## Performance Loader
154+
## Build Performance
155+
156+
W> This may degrade build performance.
157+
158+
See the [Build Performance](guides/build-performance/) guide on build tooling.
159+
142160

143-
[`awesome-typescript-loader`](https://github.com/s-panferov/awesome-typescript-loader)
161+
## Conclusion
144162

145-
Awesome TypeScript Loader has created a [wonderful explanation](https://github.com/s-panferov/awesome-typescript-loader#differences-between-ts-loader) of the difference between `awesome-typescript-loader` and `ts-loader`. The configuration for `awesome-typescript-loader` is more complex than `ts-loader`.
163+
Now that you've learned to use TypeScript with webpack to manage your JavaScript code, you can check out the next guide, which covers [Migrating from v1 to v2](guides/migrating/).

0 commit comments

Comments
 (0)