Skip to content

Commit 5511bd0

Browse files
committed
add typescript support. fixed #14
1 parent 5247a7f commit 5511bd0

File tree

8 files changed

+261
-17
lines changed

8 files changed

+261
-17
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
[![dependencies Status](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react/status.svg)](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react)
88
[![devDependencies Status](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react/dev-status.svg)](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react?type=dev)
99

10-
**_Recently updated from React 16 to 17 and Webpack 4 to 5!_**
10+
## Announcements
11+
12+
- **_Recently updated from React ~~16~~ to 17 and Webpack ~~4~~ to 5!_**
13+
- **_Recently added [TypeScript](https://www.typescriptlang.org/) Support!_**
1114

1215
## Features
1316

@@ -20,6 +23,7 @@ This boilerplate is updated with:
2023
- [React Hot Loader](https://github.com/gaearon/react-hot-loader)
2124
- [eslint-config-react-app](https://www.npmjs.com/package/eslint-config-react-app)
2225
- [Prettier](https://prettier.io/)
26+
- [TypeScript](https://www.typescriptlang.org/)
2327

2428
This boilerplate is heavily inspired by and adapted from [https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate), with additional support for React 17 features and Webpack 5.
2529

@@ -48,6 +52,10 @@ All your extension's code must be placed in the `src` folder.
4852

4953
The boilerplate is already prepared to have a popup, an options page, a background page, and a new tab page (which replaces the new tab page of your browser). But feel free to customize these.
5054

55+
## TypeScript
56+
57+
This boilerplate now supports TypeScript! The `Options` Page is implemented using TypeScript. Please refer to `src/pages/Options/` for example usages.
58+
5159
## Webpack auto-reload and HRM
5260

5361
To make your workflow much more efficient this boilerplate uses the [webpack server](https://webpack.github.io/docs/webpack-dev-server.html) to development (started with `npm start`) with auto reload feature that reloads the browser automatically every time that you save some file in your editor.

package-lock.json

Lines changed: 200 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chrome-extension-boilerplate-react",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "A chrome extension boilerplate built with React 17 and Webpack 4",
55
"license": "MIT",
66
"repository": {
@@ -16,6 +16,7 @@
1616
"@hot-loader/react-dom": "^17.0.0",
1717
"@types/chrome": "0.0.125",
1818
"@types/react": "^16.9.53",
19+
"@types/react-dom": "^16.9.8",
1920
"react": "^17.0.1",
2021
"react-dom": "^17.0.1",
2122
"react-hot-loader": "^4.13.0"
@@ -45,8 +46,11 @@
4546
"node-sass": "^4.14.1",
4647
"prettier": "^2.1.2",
4748
"sass-loader": "^10.0.4",
49+
"source-map-loader": "^1.1.2",
4850
"style-loader": "^2.0.0",
4951
"terser-webpack-plugin": "^5.0.2",
52+
"ts-loader": "^8.0.7",
53+
"typescript": "^4.0.5",
5054
"webpack": "^5.2.0",
5155
"webpack-cli": "^4.1.0",
5256
"webpack-dev-server": "^3.11.0"

src/pages/Options/Options.jsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/pages/Options/Options.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import './Options.css';
3+
4+
interface Props {
5+
title: string;
6+
}
7+
8+
const Options: React.FC<Props> = ({ title }: Props) => {
9+
return <div className="OptionsContainer">{title.toUpperCase()} Page</div>;
10+
};
11+
12+
export default Options;

src/pages/Options/index.jsx renamed to src/pages/Options/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import { render } from 'react-dom';
44
import Options from './Options';
55
import './index.css';
66

7-
render(<Options />, window.document.querySelector('#app-container'));
7+
render(
8+
<Options title={'settings'} />,
9+
window.document.querySelector('#app-container')
10+
);

tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"esModuleInterop": true,
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"module": "esnext",
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"noEmit": false,
16+
"jsx": "react"
17+
},
18+
"include": ["src"],
19+
"exclude": ["build", "node_modules"]
20+
}

0 commit comments

Comments
 (0)