Skip to content

Commit 23a4b36

Browse files
typescript working with babel and electron including App.tsx, tested only on windows
1 parent 6252650 commit 23a4b36

File tree

9 files changed

+249
-15
lines changed

9 files changed

+249
-15
lines changed

.babelrc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
],
99
"react",
1010
"stage-0"
11+
// "@babel/preset-typescript"
1112
],
12-
"plugins": [
13-
"transform-es2015-modules-commonjs"
14-
]
15-
}
13+
"plugins": ["transform-es2015-modules-commonjs"]
14+
}

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@
7777
"dependencies": {
7878
"@material-ui/core": "^1.4.1",
7979
"@material-ui/icons": "^2.0.0",
80+
"@types/react": "^16.8.14",
81+
"@types/react-dom": "^16.8.4",
8082
"autoprefixer": "^9.0.1",
8183
"babel-polyfill": "^6.26.0",
8284
"classnames": "^2.2.6",
8385
"cli-spinner": "^0.2.8",
8486
"commander": "^2.17.1",
87+
"electron": "^2.0.7",
8588
"enzyme": "^3.4.1",
8689
"konva": "^2.1.7",
8790
"localforage": "^1.7.2",
@@ -97,11 +100,12 @@
97100
"redux": "^4.0.0",
98101
"redux-devtools-extension": "^2.13.5",
99102
"redux-logger": "^3.0.6",
100-
"redux-thunk": "^2.3.0",
101-
"electron": "^2.0.7"
103+
"redux-thunk": "^2.3.0"
102104
},
103105
"devDependencies": {
104-
"babel-core": "^6.26.0",
106+
"@babel/preset-typescript": "^7.3.3",
107+
"awesome-typescript-loader": "^5.2.1",
108+
"babel-core": "^6.26.3",
105109
"babel-eslint": "^8.2.6",
106110
"babel-loader": "^7.1.4",
107111
"babel-preset-env": "^1.6.1",
@@ -131,6 +135,7 @@
131135
"postcss-loader": "^2.1.6",
132136
"sass-loader": "^7.0.3",
133137
"style-loader": "^0.20.3",
138+
"typescript": "^3.4.4",
134139
"webpack": "^4.4.0",
135140
"webpack-cli": "^3.3.0"
136141
}

src/components/App.jsx renamed to src/components/App.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ import { MuiThemeProvider } from '@material-ui/core/styles';
44
import theme from './theme';
55
import AppContainer from '../containers/AppContainer.jsx';
66

7+
interface Adam {
8+
goodguy: boolean;
9+
haswine: boolean;
10+
}
11+
712
class App extends Component {
813
render() {
14+
const adamInstance: Adam = {
15+
goodguy: true,
16+
haswine: false,
17+
};
18+
console.log(adamInstance);
919
return (
1020
<MuiThemeProvider theme={theme}>
1121
<div className="app">

src/components/__tests__/App.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
// import '../../setupTests';
33
import { shallow } from 'enzyme';
4-
import App from '../App.jsx';
4+
import App from '../App.tsx';
55
import AppContainer from '../../containers/AppContainer.jsx';
66

77
it('contains a AppContainer', () => {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'babel-polyfill';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
44
import { Provider } from 'react-redux';
5-
import App from './components/App.jsx';
5+
import App from './components/App.tsx';
66
import store from './store';
77

88
ReactDOM.render(

tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./build/",
4+
"sourceMap": true,
5+
"noImplicitAny": true,
6+
"module": "commonjs",
7+
"target": "es6",
8+
"jsx": "react"
9+
//these two options are recommended but don't work, maybe an issue with awesome-typsecript-loader vs babel
10+
// "esModuleInterop": true
11+
// "allowSyntheticDefaultImports": true
12+
},
13+
"include": ["./src/**/*"]
14+
}

tslint.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
3+
"tslint.autoFixOnSave": true,
4+
"linterOptions": {
5+
"exclude": ["config/**/*.js", "node_modules/**/*.ts"]
6+
},
7+
"rules": {
8+
"quotemark": [true, "single", "avoid-escape", "avoid-template", "jsx-double"],
9+
"jsx-boolean-value": false,
10+
"jsx-no-lambda": false,
11+
"jsx-no-multiline-js": false,
12+
"object-literal-sort-keys": false,
13+
"member-ordering": false,
14+
"no-console": false,
15+
"ordered-imports": false,
16+
"comment-format": false
17+
// "jsx-key": false,
18+
}
19+
}

webpack.config.development.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable linebreak-style */
12
const path = require('path');
23
const webpack = require('webpack');
34
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -20,6 +21,7 @@ module.exports = {
2021
},
2122
module: {
2223
rules: [
24+
{ test: /\.tsx?$/, exclude: /node-modules/, loader: 'babel-loader' },
2325
{
2426
test: /\.(js|jsx)$/,
2527
exclude: /node_modules/,
@@ -57,6 +59,7 @@ module.exports = {
5759
},
5860
],
5961
},
62+
6063
plugins: [
6164
// new CleanWebpackPlugin([BUILD_DIR]),
6265
new HtmlWebpackPlugin({

0 commit comments

Comments
 (0)