├── .gitignore
├── .vscode
├── settings.json
└── tasks.json
├── LICENSE
├── README.md
├── config
├── env.js
├── jest
│ ├── cssTransform.js
│ ├── fileTransform.js
│ └── typescriptTransform.js
├── paths.js
├── polyfills.js
├── webpack.config.dev.js
├── webpack.config.prod.js
└── webpackDevServer.config.js
├── docs
├── asset-manifest.json
├── build
│ ├── asset-manifest.json
│ ├── favicon.ico
│ ├── index.html
│ ├── manifest.json
│ ├── service-worker.js
│ └── static
│ │ └── js
│ │ ├── main.1a06dc19.js
│ │ └── main.1a06dc19.js.map
├── favicon.ico
├── index.html
├── manifest.json
├── service-worker.js
└── static
│ ├── css
│ ├── main.b7bf6768.css
│ └── main.b7bf6768.css.map
│ ├── js
│ ├── main.7bb4b72d.js
│ ├── main.7bb4b72d.js.map
│ ├── main.92c4f680.js
│ ├── main.92c4f680.js.map
│ ├── main.9c8e191e.js
│ ├── main.9c8e191e.js.map
│ ├── main.e257de5d.js
│ ├── main.e257de5d.js.map
│ ├── main.f8502358.js
│ └── main.f8502358.js.map
│ └── media
│ ├── roboto-latin-100.987b8457.woff2
│ ├── roboto-latin-100.e9dbbe8a.woff
│ ├── roboto-latin-100italic.6232f43d.woff2
│ ├── roboto-latin-100italic.d704bb3d.woff
│ ├── roboto-latin-300.55536c8e.woff2
│ ├── roboto-latin-300.a1471d1d.woff
│ ├── roboto-latin-300italic.210a7c78.woff
│ ├── roboto-latin-300italic.d69924b9.woff2
│ ├── roboto-latin-400.5d4aeb4e.woff2
│ ├── roboto-latin-400.bafb105b.woff
│ ├── roboto-latin-400italic.9680d5a0.woff
│ ├── roboto-latin-400italic.d8bcbe72.woff2
│ ├── roboto-latin-500.28546717.woff2
│ ├── roboto-latin-500.de8b7431.woff
│ ├── roboto-latin-500italic.510dec37.woff2
│ ├── roboto-latin-500italic.ffcc050b.woff
│ ├── roboto-latin-700.037d8304.woff2
│ ├── roboto-latin-700.cf6613d1.woff
│ ├── roboto-latin-700italic.010c1aee.woff2
│ ├── roboto-latin-700italic.846d1890.woff
│ ├── roboto-latin-900.19b7a0ad.woff2
│ ├── roboto-latin-900.8c2ade50.woff
│ ├── roboto-latin-900italic.7b770d6c.woff2
│ └── roboto-latin-900italic.bc833e72.woff
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
├── scripts
├── build.js
├── start.js
└── test.js
├── snippets
└── tsx.json
├── src
├── App.tsx
├── Counter.tsx
├── CounterContainer.tsx
├── CounterDisplay.tsx
├── CounterForm.tsx
├── SimplePageLayout.tsx
├── Util.tsx
├── assets
│ └── images
│ │ └── logo.svg
├── index.tsx
├── registerServiceWorker.ts
└── tests
│ └── App.test.tsx
├── tsconfig.json
├── tsconfig.test.json
└── tslint.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .env*
14 | /src/registerServiceWorker.js
15 |
16 | npm-debug.log*
17 | yarn-debug.log*
18 | yarn-error.log*
19 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.tabSize": 2,
3 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "typescript",
8 | "tsconfig": "tsconfig.json",
9 | "option": "watch",
10 | "problemMatcher": [
11 | "$tsc-watch"
12 | ]
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Clemex Technologies
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # A Template for TypeScript Projects using React and Redux
2 |
3 | This project is a simple template project developed by [Clemex Technologies](https://github.com/Clemex) for bootstrapping new React/Redux applications using TypeScript. We started from the [TypeScript React Starter](https://github.com/Microsoft/TypeScript-React-Starter) from Microsoft and added several libraries and a more complete example application.
4 |
5 | The project contains the source code for a simple counter application that demonstrates the usage of React, Redux, Redux-Form, Redux-Logger, Material-UI, and React-UI all written in TypeScript. This was inspired by [the Counter project by Leyka](https://github.com/Leyka/learning-react/tree/master/react-redux) a simple app which increments or decrements a counter using React/Redux which in turn was based on [the React/Redux counter example](https://github.com/reactjs/redux/tree/master/examples/counter/src).
6 |
7 | You can [try out this sample project here](https://clemex.github.io/typescript-react-template/).
8 |
9 | # Motivation
10 |
11 | [React](typescriptlang.org) is a very powerful UI creation framework for JavaScript applications, and [Redux](https://redux.js.org/) is a useful and simple state management system for JavaScript applications.
12 |
13 | At [Clemex](https://github.com/Clemex) we have found that React and Redux works very well with [TypeScript](typescriptlang.org), but it is not yet obvious what libraries work best with this stack for production code, and what the best practices are for producing scalable code. This project has served as a test bed for us when developing new features, and experimenting with different techniques.
14 |
15 | There are a couple of pre-existing React/Redux/TypeScript starters and template projects such as the [TypeScript React Starter](https://github.com/Microsoft/TypeScript-React-Starter) we started from, but we wanted to create a starter kit that more closely resembled our development stack and that would make it easier for new team members to onboard.
16 |
17 | # Building and Running the Project
18 |
19 | After cloning the repository from GitHub use the command `npm install` to install all of the tools and dependencies.
20 |
21 | The command `npm run start` will compile and launch the project in your browser at the location `http://localhost:3000/` with a watcher which will rebuild the project whenever any source file is changed.
22 |
23 | You can use `npm run build` to create a production build. For more build options take a look at the `package.json` file.
24 |
25 | # Libraries
26 |
27 | This project demonstrates the use of the following libraries in TypeScript:
28 |
29 | * [React](https://github.com/Clemex/typescript-react-template) - UI Front-end
30 | * [React Intl](https://github.com/yahoo/react-intl) - Application internationalization support
31 | * [Redux](https://redux.js.org/) - Centralized state management
32 | * [Redux Form](https://redux-form.com/7.2.1/) - Form state management via Redux
33 | * [Redux Logger](https://github.com/evgenyrodionov/redux-logger) - Redux logger middleware
34 | * [Material UI](https://www.material-ui.com/) - React components that implement Google's Material Design
35 |
36 | ## Development Tools
37 |
38 | At Clemex we are using the following development tools:
39 |
40 | * [NPM](https://www.npmjs.com/) : Node Package Manager
41 | * [Node](https://nodejs.org) : JavaScript runtime built on Chrome's V8 JavaScript engine
42 | * [TypeScript](https://www.typescriptlang.org/) : Statically typed Javascript that compiles to plain Javascript
43 | * [TS-Lint](https://palantir.github.io/tslint/) : Linter for the TypeScript language
44 | * [Webpack](https://webpack.js.org/) : Let you bundle JavaScript files for usage in a browser (needed for React)
45 | * [Jest](https://facebook.github.io/jest/) : Test all JavaScript code including React applications
46 | * [React Developer Tools for Chrome](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
47 | * [Redux DevTools for Chrome](https://chrome.google.com/webstore/detail/redux-devtools)
48 | * [Visual Studio Code](https://code.visualstudio.com/) : Source code editor by Microsoft for Windows, Linux and macOS
49 |
50 | ## Contributing
51 |
52 | If you find any issues or have ideas for improvements we would love to hear from you. You can either log an [issue/improvement](https://github.com/Clemex/typescript-react-template/issues), or submit a [pull request](https://github.com/Clemex/typescript-react-template/pulls).
53 |
54 | ## Additional Resources
55 |
56 | Here are some useful links for learning specifically more about TypeScript, React, and Redux on the internet.
57 |
58 | * [TypeScript React Starter](https://github.com/Microsoft/TypeScript-React-Starter) from Microsoft
59 | * [TypeScript React Conversion Guide](https://github.com/Microsoft/TypeScript-React-Conversion-Guide) from Microsoft
60 | * [Static Typing in React & Redux using TypeScript](https://github.com/piotrwitek/react-redux-typescript-guide) by Piotr Witek
61 | * [Typesafe Action Creation for Redux](https://github.com/piotrwitek/typesafe-actions) by Piotr Witek
62 | * [TypeScript Guide for Material UI Next](https://material-ui-next.com/guides/typescript/) from Material UI
63 | * [React JavaScript to TypeScript Transform](https://github.com/lyft/react-javascript-to-typescript-transform) from Lyft
64 | * [Getting Started with React and TypeScript](https://javascriptplayground.com/react-typescript/) by Jack Franklin
65 | * [TypeScript, React, and Redux](http://www.mattgreer.org/articles/typescript-react-and-redux/) by Matt Greer
66 | * [TypeScript at Slack](https://slack.engineering/typescript-at-slack-a81307fa288d) by Felix Rieseberg
67 | * [TypeScript at Lyft](https://eng.lyft.com/typescript-at-lyft-64f0702346ea) by Mohsen Azimi
68 |
69 |
70 |
--------------------------------------------------------------------------------
/config/env.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const fs = require('fs');
4 | const path = require('path');
5 | const paths = require('./paths');
6 |
7 | // Make sure that including paths.js after env.js will read .env variables.
8 | delete require.cache[require.resolve('./paths')];
9 |
10 | const NODE_ENV = process.env.NODE_ENV;
11 | if (!NODE_ENV) {
12 | throw new Error(
13 | 'The NODE_ENV environment variable is required but was not specified.'
14 | );
15 | }
16 |
17 | // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
18 | var dotenvFiles = [
19 | `${paths.dotenv}.${NODE_ENV}.local`,
20 | `${paths.dotenv}.${NODE_ENV}`,
21 | // Don't include `.env.local` for `test` environment
22 | // since normally you expect tests to produce the same
23 | // results for everyone
24 | NODE_ENV !== 'test' && `${paths.dotenv}.local`,
25 | paths.dotenv,
26 | ].filter(Boolean);
27 |
28 | // Load environment variables from .env* files. Suppress warnings using silent
29 | // if this file is missing. dotenv will never modify any environment variables
30 | // that have already been set.
31 | // https://github.com/motdotla/dotenv
32 | dotenvFiles.forEach(dotenvFile => {
33 | if (fs.existsSync(dotenvFile)) {
34 | require('dotenv').config({
35 | path: dotenvFile,
36 | });
37 | }
38 | });
39 |
40 | // We support resolving modules according to `NODE_PATH`.
41 | // This lets you use absolute paths in imports inside large monorepos:
42 | // https://github.com/facebookincubator/create-react-app/issues/253.
43 | // It works similar to `NODE_PATH` in Node itself:
44 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
45 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
46 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
47 | // https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
48 | // We also resolve them to make sure all tools using them work consistently.
49 | const appDirectory = fs.realpathSync(process.cwd());
50 | process.env.NODE_PATH = (process.env.NODE_PATH || '')
51 | .split(path.delimiter)
52 | .filter(folder => folder && !path.isAbsolute(folder))
53 | .map(folder => path.resolve(appDirectory, folder))
54 | .join(path.delimiter);
55 |
56 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
57 | // injected into the application via DefinePlugin in Webpack configuration.
58 | const REACT_APP = /^REACT_APP_/i;
59 |
60 | function getClientEnvironment(publicUrl) {
61 | const raw = Object.keys(process.env)
62 | .filter(key => REACT_APP.test(key))
63 | .reduce(
64 | (env, key) => {
65 | env[key] = process.env[key];
66 | return env;
67 | },
68 | {
69 | // Useful for determining whether we’re running in production mode.
70 | // Most importantly, it switches React into the correct mode.
71 | NODE_ENV: process.env.NODE_ENV || 'development',
72 | // Useful for resolving the correct path to static assets in `public`.
73 | // For example,
.
74 | // This should only be used as an escape hatch. Normally you would put
75 | // images into the `src` and `import` them in code to get their paths.
76 | PUBLIC_URL: publicUrl,
77 | }
78 | );
79 | // Stringify all values so we can feed into Webpack DefinePlugin
80 | const stringified = {
81 | 'process.env': Object.keys(raw).reduce(
82 | (env, key) => {
83 | env[key] = JSON.stringify(raw[key]);
84 | return env;
85 | },
86 | {}
87 | ),
88 | };
89 |
90 | return { raw, stringified };
91 | }
92 |
93 | module.exports = getClientEnvironment;
94 |
--------------------------------------------------------------------------------
/config/jest/cssTransform.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // This is a custom Jest transformer turning style imports into empty objects.
4 | // http://facebook.github.io/jest/docs/tutorial-webpack.html
5 |
6 | module.exports = {
7 | process() {
8 | return 'module.exports = {};';
9 | },
10 | getCacheKey() {
11 | // The output is always the same.
12 | return 'cssTransform';
13 | },
14 | };
15 |
--------------------------------------------------------------------------------
/config/jest/fileTransform.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const path = require('path');
4 |
5 | // This is a custom Jest transformer turning file imports into filenames.
6 | // http://facebook.github.io/jest/docs/tutorial-webpack.html
7 |
8 | module.exports = {
9 | process(src, filename) {
10 | return `module.exports = ${JSON.stringify(path.basename(filename))};`;
11 | },
12 | };
13 |
--------------------------------------------------------------------------------
/config/jest/typescriptTransform.js:
--------------------------------------------------------------------------------
1 | // Copyright 2004-present Facebook. All Rights Reserved.
2 |
3 | 'use strict';
4 |
5 | const tsJestPreprocessor = require('ts-jest/preprocessor');
6 |
7 | module.exports = tsJestPreprocessor;
8 |
--------------------------------------------------------------------------------
/config/paths.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const path = require('path');
4 | const fs = require('fs');
5 | const url = require('url');
6 |
7 | // Make sure any symlinks in the project folder are resolved:
8 | // https://github.com/facebookincubator/create-react-app/issues/637
9 | const appDirectory = fs.realpathSync(process.cwd());
10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
11 |
12 | const envPublicUrl = process.env.PUBLIC_URL;
13 |
14 | function ensureSlash(path, needsSlash) {
15 | const hasSlash = path.endsWith('/');
16 | if (hasSlash && !needsSlash) {
17 | return path.substr(path, path.length - 1);
18 | } else if (!hasSlash && needsSlash) {
19 | return `${path}/`;
20 | } else {
21 | return path;
22 | }
23 | }
24 |
25 | const getPublicUrl = appPackageJson =>
26 | envPublicUrl || require(appPackageJson).homepage;
27 |
28 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer
29 | // "public path" at which the app is served.
30 | // Webpack needs to know it to put the right