Skip to content

Commit db640f6

Browse files
committed
typescript w/o babel example
1 parent e8f8935 commit db640f6

File tree

9 files changed

+4790
-0
lines changed

9 files changed

+4790
-0
lines changed

examples/typescript-no-babel/.babelrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["env", "react"],
3+
"plugins": ["transform-class-properties"]
4+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "hot-pure-typescript",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"scripts": {
6+
"start": "webpack-dev-server --hot"
7+
},
8+
"devDependencies": {
9+
"awesome-typescript-loader": "^3.4.1",
10+
"babel-core": "^6.26.0",
11+
"babel-loader": "^7.1.2",
12+
"babel-plugin-transform-class-properties": "^6.24.1",
13+
"babel-preset-env": "^1.6.1",
14+
"babel-preset-react": "^6.24.1",
15+
"html-webpack-plugin": "^2.30.1",
16+
"typescript": "^2.6.2",
17+
"webpack": "^3.10.0",
18+
"webpack-dev-server": "^2.9.7"
19+
},
20+
"dependencies": {
21+
"@types/react": "^16.0.31",
22+
"@types/react-dom": "^16.0.3",
23+
"react": "^16.2.0",
24+
"react-dom": "^16.2.0",
25+
"react-hot-loader": "^4.0.1"
26+
}
27+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import { hot } from 'react-hot-loader'
3+
import Counter from './Counter'
4+
5+
const App = () => (
6+
<h1>
7+
Hello, world!<br />
8+
You can update this text, and it will work
9+
<Counter />
10+
</h1>
11+
)
12+
13+
export default hot(module)(App)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as React from 'react'
2+
3+
class Counter extends React.Component<{}, { count: number }> {
4+
interval: number;
5+
6+
constructor(props : any) {
7+
super(props)
8+
this.state = { count: 0 }
9+
}
10+
11+
componentDidMount() {
12+
this.interval = window.setInterval(
13+
() => this.setState(prevState => ({ count: prevState.count + 1 })),
14+
200,
15+
)
16+
}
17+
18+
generateString1() {
19+
// you can update this method, and it will work
20+
return "1";
21+
}
22+
23+
generateString2 = () => {
24+
// this one will not
25+
return "1";
26+
}
27+
28+
componentWillUnmount() {
29+
clearInterval(this.interval)
30+
}
31+
32+
render() {
33+
return <span>{this.state.count} - {this.generateString1()} - {this.generateString2()}</span>
34+
}
35+
}
36+
37+
export default Counter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as React from 'react'
2+
import { render } from 'react-dom'
3+
import App from './App'
4+
5+
const root = document.createElement('div')
6+
document.body.appendChild(root)
7+
8+
render(<App />, root)
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist/",
4+
"sourceMap": true,
5+
"noImplicitAny": true,
6+
"module": "commonjs",
7+
"target": "es6",
8+
"jsx": "react"
9+
},
10+
"include": ["./src/**/*"]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-disable */
2+
const path = require('path')
3+
const webpack = require('webpack')
4+
const HtmlWebpackPlugin = require('html-webpack-plugin')
5+
6+
module.exports = {
7+
entry: ['./src/index'],
8+
output: {
9+
path: path.join(__dirname, 'dist'),
10+
filename: 'bundle.js',
11+
},
12+
module: {
13+
rules: [
14+
{
15+
test: /\.tsx?$/,
16+
use: ['awesome-typescript-loader'],
17+
},
18+
],
19+
},
20+
resolve: {
21+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
22+
},
23+
plugins: [new HtmlWebpackPlugin(), new webpack.NamedModulesPlugin()],
24+
}

0 commit comments

Comments
 (0)