Skip to content

Commit 9ace79b

Browse files
author
Orta
authored
Merge pull request microsoft#22 from matthewliuswims/house-keeping-upgrades
Housekeeping upgrades
2 parents 6544864 + 3a407d1 commit 9ace79b

File tree

9 files changed

+10143
-25
lines changed

9 files changed

+10143
-25
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ cd TicTacToe_JS
4545
npm install
4646
```
4747

48-
Additionally, install TypeScript (2.3 or higher), [awesome-typescript-loader](https://www.npmjs.com/package/awesome-typescript-loader) and [source-map-loader](https://www.npmjs.com/package/source-map-loader) as dev dependencies if you haven't. awesome-typescript-loader is a Webpack plugin that helps you compile TypeScript code to JavaScript, much like babel-loader for Babel. There are also other alternative loaders for TypeScript, such as [ts-loader](https://github.com/TypeStrong/ts-loader). source-map-loader adds source map support for debugging.
48+
Additionally, install TypeScript (3 or higher), [ts-loader](https://www.npmjs.com/package/ts-loader) and [source-map-loader](https://www.npmjs.com/package/source-map-loader) as dev dependencies if you haven't. ts-loader is a Webpack plugin that helps you compile TypeScript code to JavaScript, much like babel-loader for Babel. There are also other alternative loaders for TypeScript! Source-map-loader adds source map support for debugging.
4949

5050
```sh
51-
npm install --save-dev typescript awesome-typescript-loader source-map-loader
51+
npm install --save-dev typescript ts-loader source-map-loader
5252
```
5353

5454
Get the type declaration files (.d.ts files) from [@types](https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/) for any library in use. For this project, we have React and ReactDOM.
@@ -90,7 +90,7 @@ To add TypeScript compilation as part of our build process, you need to modify t
9090
Generally, we need to change `webpack.config.js` in a few ways,
9191

9292
1. Expand the module resolution extensions to include `.ts` and `.tsx` files.
93-
2. Replace `babel-loader` with `awesome-typescript-loader`.
93+
2. Replace `babel-loader` with `ts-loader`.
9494
3. Add source-map support.
9595

9696
Let's modify `webpack.configure.js` as below,
@@ -109,7 +109,7 @@ module.exports = {
109109
module: {
110110
rules: [
111111
// changed from { test: /\.jsx?$/, use: { loader: 'babel-loader' } },
112-
{ test: /\.(t|j)sx?$/, use: { loader: 'awesome-typescript-loader' } },
112+
{ test: /\.(t|j)sx?$/, use: { loader: 'ts-loader' } },
113113
// addition - add source-map support
114114
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
115115
]
@@ -155,7 +155,7 @@ On line 1 `import React from "react";`, change the import statement to `import *
155155

156156
On line 3 `export class GameStateBar extends React.Component {`, change the class declaration to `export class GameStateBar extends React.Component<any, any> {`. The type declaration of `React.Component` uses [generic types](https://www.typescriptlang.org/docs/handbook/generics.html) and requires providing the types for the property and state object for the component. The use of `any` allows us to pass in any value as the property or state object, which is not useful in terms of type checking but suffices as minimum effort to appease the compiler.
157157

158-
By now, awesome-typescript-loader should be able to successfully compile this TypeScript component to JavaScript. Again, try bundling the app with the following command and then open `index.html` in a browser,
158+
By now, ts-loader should be able to successfully compile this TypeScript component to JavaScript. Again, try bundling the app with the following command and then open `index.html` in a browser,
159159

160160
```sh
161161
npx webpack

TicTacToe_JS/.babelrc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"presets": ["es2015", "react"]
3-
}
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-react"
5+
]
6+
}

TicTacToe_JS/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<meta charset="utf-8" />
55
<title>TicTacToe with TypeScript and React</title>
66
<link rel="stylesheet" href="css/style.css">
7-
<script src="./node_modules/react/dist/react.js"></script>
8-
<script src="./node_modules/react-dom/dist/react-dom.js"></script>
7+
<script src="./node_modules/react/umd/react.production.min.js"></script>
8+
<script src="./node_modules/react-dom/umd/react-dom.production.min.js"></script>
99
</head>
1010
<body>
1111
<div id="content"></div>

0 commit comments

Comments
 (0)