Skip to content

Instantly share code, notes, and snippets.

@frankievalentine
Last active October 9, 2020 16:33
Show Gist options
  • Save frankievalentine/82d0076cd7dae78ea841641b15a17e5f to your computer and use it in GitHub Desktop.
Save frankievalentine/82d0076cd7dae78ea841641b15a17e5f to your computer and use it in GitHub Desktop.
react-typescript-parcel

Directory Setup

├── src
│   ├── App.tsx
├── components
│   ├── Hello.tsx
├── styles
│   ├── index.css
├── index.html
├── package.json
└── tsconfig.json
import * as React from "react";
import { render } from "react-dom";
import { Hello } from "./Hello";
// import './styles/index.css'
const App = () => {
return (
<div>
{/* make sure Typescript is working by using number type */}
<Hello compiler="Parcel" framework={123} />
</div>
);
};
render(<App />, document.getElementById("app"));
mkdir [dirname]
cd [dirname]
yarn init
git init
touch index.html .gitignore tsconfig.json .README
echo -e "node_modules\nyarn.lock" >> .gitignore
mkdir src && cd src && touch App.tsx && mkdir Components && cd Components && touch Hello.tsx
code .
# add code to files from gist
cd ../..
yarn add react react-dom --save
yarn add parcel-bundler typescript @types/react @types/react-dom --save-dev
tsc --init
# add to tsconfig.json from template in gist
import * as React from "react";
export interface HelloProps {
compiler: string;
framework: string;
}
export class Hello extends React.Component<HelloProps, {}> {
render() {
return (
<h1>
Hello from {this.props.compiler} and {this.props.framework}!
</h1>
);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>react-typescript-parcel</title>
</head>
<body>
<div id="app"></div>
<script src="./index.tsx"></script>
</body>
</html>
"scripts": {
"start": "parcel src/index.html",
"build": "parcel build src/index.html"
},
// assuming your ts sources are in ./src/
{
"compilerOptions": {
"jsx": "react",
"target": "es6",
"module": "commonjs",
"strict": true,
"baseUrl": "./src",
"paths": {
"~*": ["./*"]
},
},
"include": ["src/**/*"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment