Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit cb1cd70

Browse files
committed
Hello world with react and typescript
0 parents  commit cb1cd70

File tree

13 files changed

+757
-0
lines changed

13 files changed

+757
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
*.iml
3+
.idea/*
4+
dist/*

index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Hello React!</title>
6+
</head>
7+
<body>
8+
<div id="example"></div>
9+
10+
<!-- Dependencies -->
11+
<script src="./node_modules/react/dist/react.js"></script>
12+
<script src="./node_modules/react-dom/dist/react-dom.js"></script>
13+
14+
<!-- Main -->
15+
<script src="./dist/bundle.js"></script>
16+
</body>
17+
</html>

package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "typescript-react-starter",
3+
"version": "1.0.0",
4+
"description": "React Typescript Setup",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest",
8+
"serve": "node_modules/.bin/webpack-dev-server"
9+
},
10+
"keywords": [
11+
"typescript",
12+
"react",
13+
"starter",
14+
"example"
15+
],
16+
"author": "Alex Thornburg",
17+
"license": "ISC",
18+
"devDependencies": {
19+
"@types/enzyme": "^2.7.7",
20+
"@types/jasmine": "^2.5.47",
21+
"awesome-typescript-loader": "^3.1.2",
22+
"enzyme": "^2.8.0",
23+
"jest": "^19.0.2",
24+
"karma": "^1.6.0",
25+
"karma-chrome-launcher": "^2.0.0",
26+
"karma-typescript": "^3.0.0",
27+
"karma-typescript-preprocessor": "^0.3.1",
28+
"react-addons-test-utils": "^15.5.1",
29+
"source-map-loader": "^0.2.1",
30+
"typescript": "^2.2.2",
31+
"webpack-dev-server": "^2.4.2"
32+
},
33+
"dependencies": {
34+
"@types/react": "^15.0.21",
35+
"@types/react-dom": "^0.14.23",
36+
"react": "^15.5.3",
37+
"react-dom": "^15.5.3",
38+
"webpack": "^2.3.3"
39+
},
40+
"jest": {
41+
"moduleFileExtensions": [
42+
"ts",
43+
"tsx",
44+
"js"
45+
],
46+
"transform": {
47+
"^.+\\.(ts|tsx)$": "<rootDir>/preprocessor.js"
48+
},
49+
"testMatch": [
50+
"**/__test__/*.(ts|tsx)"
51+
]
52+
}
53+
}

preprocessor.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const tsc = require('typescript');
2+
const tsConfig = require('./tsconfig.json');
3+
4+
module.exports = {
5+
process(src, path) {
6+
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
7+
return tsc.transpile(
8+
src,
9+
tsConfig.compilerOptions,
10+
path,
11+
[]
12+
);
13+
}
14+
return src;
15+
},
16+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from "react";
2+
import {shallow} from "enzyme";
3+
import {Hello} from "../hello";
4+
5+
describe("Hello Component", () => {
6+
let helloComponent: any;
7+
beforeEach(() => {
8+
helloComponent = shallow(<Hello/>);
9+
});
10+
11+
it("says hello", () => {
12+
expect(helloComponent.find("h1").text()).toContain("Hello typescript and react!");
13+
});
14+
});

src/components/hello.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as React from "react";
2+
3+
export interface HelloProps {}
4+
5+
// 'HelloProps' describes the shape of props.
6+
// State is never set so we use the 'undefined' type.
7+
export class Hello extends React.Component<HelloProps, undefined> {
8+
render() {
9+
return <h1>Hello typescript and react!</h1>;
10+
}
11+
}

src/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as React from "react";
2+
import * as ReactDOM from "react-dom";
3+
4+
import { Hello } from "./components/hello";
5+
6+
ReactDOM.render(
7+
<Hello/>,
8+
document.getElementById("example")
9+
);

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist/",
4+
"sourceMap": true,
5+
"noImplicitAny": true,
6+
"module": "commonjs",
7+
"target": "es6",
8+
"jsx": "react"
9+
},
10+
"include": [
11+
"./src/**/*"
12+
],
13+
"files": [
14+
"src/**/*"
15+
]
16+
}

typings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"enzyme": "registry:dt/enzyme#2.7.0+20170320235509"
4+
}
5+
}

typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="modules/enzyme/index.d.ts" />

0 commit comments

Comments
 (0)