From fe8f8ee721fe4d65e9eab325823939da36ab22d8 Mon Sep 17 00:00:00 2001 From: github0013 Date: Fri, 29 Dec 2017 12:10:08 +0900 Subject: [PATCH] Update typescript.md --- docs/typescript.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/typescript.md b/docs/typescript.md index c85416baf..1cc354f90 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -35,7 +35,21 @@ yarn add ts-loader typescript @types/react @types/react-dom } ``` -3. Finally add `.tsx` to the list of extensions in `config/webpacker.yml` +3. Edit `config/webpack/environment.js` and add ts-loader (webpacker@3.2.0 and above) + +```js +const { environment } = require("@rails/webpacker"); + +environment.loaders.set("typescript", { + test: /\.(tsx|ts)?$/, + use: "ts-loader" +}); + +module.exports = environment; +``` + + +4. Finally add `.tsx` to the list of extensions in `config/webpacker.yml` and rename your generated `hello_react.js` using react installer to `hello_react.tsx` and make it valid typescript and now you can use typescript, JSX with React.