Skip to content

Commit

Permalink
add typescript support. fixed #14
Browse files Browse the repository at this point in the history
  • Loading branch information
lxieyang committed Oct 27, 2020
1 parent 5247a7f commit 5511bd0
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 17 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
[![dependencies Status](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react/status.svg)](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react)
[![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)

**_Recently updated from React 16 to 17 and Webpack 4 to 5!_**
## Announcements

- **_Recently updated from React ~~16~~ to 17 and Webpack ~~4~~ to 5!_**
- **_Recently added [TypeScript](https://www.typescriptlang.org/) Support!_**

## Features

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

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.

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

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.

## TypeScript

This boilerplate now supports TypeScript! The `Options` Page is implemented using TypeScript. Please refer to `src/pages/Options/` for example usages.

## Webpack auto-reload and HRM

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.
Expand Down
201 changes: 200 additions & 1 deletion package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-extension-boilerplate-react",
"version": "3.0.1",
"version": "3.1.0",
"description": "A chrome extension boilerplate built with React 17 and Webpack 4",
"license": "MIT",
"repository": {
Expand All @@ -16,6 +16,7 @@
"@hot-loader/react-dom": "^17.0.0",
"@types/chrome": "0.0.125",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-hot-loader": "^4.13.0"
Expand Down Expand Up @@ -45,8 +46,11 @@
"node-sass": "^4.14.1",
"prettier": "^2.1.2",
"sass-loader": "^10.0.4",
"source-map-loader": "^1.1.2",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.0.2",
"ts-loader": "^8.0.7",
"typescript": "^4.0.5",
"webpack": "^5.2.0",
"webpack-cli": "^4.1.0",
"webpack-dev-server": "^3.11.0"
Expand Down
10 changes: 0 additions & 10 deletions src/pages/Options/Options.jsx

This file was deleted.

12 changes: 12 additions & 0 deletions src/pages/Options/Options.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import './Options.css';

interface Props {
title: string;
}

const Options: React.FC<Props> = ({ title }: Props) => {
return <div className="OptionsContainer">{title.toUpperCase()} Page</div>;
};

export default Options;
5 changes: 4 additions & 1 deletion src/pages/Options/index.jsx → src/pages/Options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import { render } from 'react-dom';
import Options from './Options';
import './index.css';

render(<Options />, window.document.querySelector('#app-container'));
render(
<Options title={'settings'} />,
window.document.querySelector('#app-container')
);
20 changes: 20 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": false,
"jsx": "react"
},
"include": ["src"],
"exclude": ["build", "node_modules"]
}
Loading

0 comments on commit 5511bd0

Please sign in to comment.