Skip to content

Commit

Permalink
- rails webpacker:install:typescript
Browse files Browse the repository at this point in the history
- Add "allowSyntheticDefaultImports": true to tsconfig
- Convert component to tsx and FC component
- yarn remove babel-plugin-transform-react-remove-prop-types prop-types
  • Loading branch information
haruhikonyan committed Aug 10, 2021
1 parent 7bb2358 commit 655dc59
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 66 deletions.
16 changes: 0 additions & 16 deletions app/javascript/components/HelloWorld.js

This file was deleted.

12 changes: 12 additions & 0 deletions app/javascript/components/HelloWorld.tsx
@@ -0,0 +1,12 @@
import React from "react"

type Props = {
greeting: string
}

const HelloWorld: React.VFC<Props> = ({ greeting }) => {
return <>
Greetingts: {greeting}
</>
}
export default HelloWorld
26 changes: 0 additions & 26 deletions app/javascript/packs/hello_react.jsx

This file was deleted.

4 changes: 4 additions & 0 deletions app/javascript/packs/hello_typescript.ts
@@ -0,0 +1,4 @@
// Run this example by adding <%= javascript_pack_tag 'hello_typescript' %> to the head of your layout file,
// like app/views/layouts/application.html.erb.

console.log('Hello world from typescript');
3 changes: 2 additions & 1 deletion babel.config.js
Expand Up @@ -43,7 +43,8 @@ module.exports = function(api) {
development: isDevelopmentEnv || isTestEnv,
useBuiltIns: true
}
]
],
['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
Expand Down
2 changes: 2 additions & 0 deletions config/webpacker.yml
Expand Up @@ -33,6 +33,8 @@ default: &default
- .woff2

extensions:
- .tsx
- .ts
- .jsx
- .mjs
- .js
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -3,16 +3,18 @@
"private": true,
"dependencies": {
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.4.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"prop-types": "^15.7.2",
"@types/react": "^17.0.16",
"@types/react-dom": "^17.0.9",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react_ujs": "^2.6.1",
"turbolinks": "^5.2.0",
"typescript": "^4.3.5",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
Expand Down
25 changes: 25 additions & 0 deletions tsconfig.json
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es6",
"dom"
],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"jsx": "react",
"noEmit": true,
"allowSyntheticDefaultImports": true
},
"exclude": [
"**/*.spec.ts",
"node_modules",
"vendor",
"public"
],
"compileOnSave": false
}
84 changes: 63 additions & 21 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 655dc59

Please sign in to comment.