Skip to content

Commit 5baa79a

Browse files
committed
first commit
0 parents  commit 5baa79a

22 files changed

+6839
-0
lines changed

.babelrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env",
4+
[
5+
"@babel/preset-react",
6+
{
7+
"runtime": "automatic"
8+
}
9+
],
10+
"@babel/preset-typescript"
11+
],
12+
"plugins": [
13+
[
14+
"@babel/plugin-transform-runtime",
15+
{
16+
"regenerator": true
17+
}
18+
]
19+
]
20+
}

.eslintrc.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
ecmaVersion: 2020,
5+
sourceType: 'module',
6+
},
7+
settings: {
8+
react: {
9+
version: 'detect',
10+
},
11+
},
12+
extends: [
13+
'plugin:react/recommended',
14+
'plugin:react-hooks/recommended',
15+
'plugin:@typescript-eslint/recommended',
16+
'plugin:import/errors',
17+
'plugin:import/warnings',
18+
'plugin:import/typescript',
19+
'plugin:jsx-a11y/recommended',
20+
'plugin:eslint-comments/recommended',
21+
'prettier/@typescript-eslint',
22+
'plugin:prettier/recommended',
23+
],
24+
rules: {
25+
'no-unused-vars': 'off',
26+
'@typescript-eslint/no-unused-vars': ['error'],
27+
'@typescript-eslint/no-var-requires': 'off',
28+
'react/prop-types': 'off',
29+
'react/jsx-uses-react': 'off',
30+
'react/react-in-jsx-scope': 'off',
31+
'@typescript-eslint/explicit-module-boundary-types': 'off',
32+
},
33+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
node_modules
3+
4+
yarn-error.log

.prettierrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
semi: false,
3+
trailingComma: 'es5',
4+
singleQuote: true,
5+
printWidth: 80,
6+
tabWidth: 2,
7+
endOfLine: 'auto'
8+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"i18n-ally.localesPaths": [
3+
"src/i18n"
4+
],
5+
"i18n-ally.keystyle": "nested"
6+
}

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Download the starter kit
2+
3+
npx degit https://github.com/gopinav/React-TypeScript-Webpack-Starter my-app
4+
5+
## Install dependencies
6+
7+
cd my-app &&
8+
yarn
9+
10+
## Run dev server
11+
12+
yarn start
13+
14+
## Build
15+
16+
yarn build

package.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "react-typescript-webpack-starter",
3+
"version": "1.0.0",
4+
"description": "A starter template for React with Typescript using Webpack 5",
5+
"scripts": {
6+
"start": "webpack serve --config webpack/webpack.config.js --env env=dev",
7+
"build": "webpack --config webpack/webpack.config.js --env env=prod",
8+
"lint": "eslint --fix \"./src/**/*.{js,jsx,ts,tsx,json}\"",
9+
"format": "prettier --write \"./src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"keywords": [
13+
"React",
14+
"TypeScript",
15+
"Webpack 5",
16+
"Starter Template",
17+
"Boilerplate"
18+
],
19+
"author": "Vishwas",
20+
"license": "MIT",
21+
"dependencies": {
22+
"i18next": "^22.4.9",
23+
"i18next-browser-languagedetector": "^7.0.1",
24+
"react": "^17.0.1",
25+
"react-dom": "^17.0.1",
26+
"react-i18next": "^12.1.4"
27+
},
28+
"devDependencies": {
29+
"@babel/core": "^7.12.16",
30+
"@babel/plugin-transform-runtime": "^7.13.10",
31+
"@babel/preset-env": "^7.12.16",
32+
"@babel/preset-react": "^7.12.13",
33+
"@babel/preset-typescript": "^7.12.16",
34+
"@babel/runtime": "^7.13.10",
35+
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
36+
"@types/react": "^17.0.2",
37+
"@types/react-dom": "^17.0.1",
38+
"@typescript-eslint/eslint-plugin": "^4.15.0",
39+
"@typescript-eslint/parser": "^4.15.0",
40+
"babel-loader": "^8.2.2",
41+
"clean-webpack-plugin": "^3.0.0",
42+
"css-loader": "^5.0.2",
43+
"eslint": "^7.19.0",
44+
"eslint-config-prettier": "^7.2.0",
45+
"eslint-plugin-eslint-comments": "^3.2.0",
46+
"eslint-plugin-import": "^2.22.1",
47+
"eslint-plugin-jsx-a11y": "^6.4.1",
48+
"eslint-plugin-prettier": "^3.3.1",
49+
"eslint-plugin-react": "^7.22.0",
50+
"eslint-plugin-react-hooks": "^4.2.0",
51+
"html-webpack-plugin": "^5.1.0",
52+
"husky": "4",
53+
"lint-staged": "^10.5.4",
54+
"prettier": "^2.2.1",
55+
"react-refresh": "^0.9.0",
56+
"style-loader": "^2.0.0",
57+
"typescript": "^4.1.5",
58+
"webpack": "^5.21.2",
59+
"webpack-cli": "^4.5.0",
60+
"webpack-dev-server": "^3.11.2",
61+
"webpack-merge": "^5.7.3"
62+
},
63+
"husky": {
64+
"hooks": {
65+
"pre-commit": "lint-staged"
66+
}
67+
},
68+
"lint-staged": {
69+
"src/**/*.{js,jsx,ts,tsx,json}": [
70+
"eslint --fix"
71+
],
72+
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
73+
"prettier --write"
74+
]
75+
}
76+
}

src/@types/global.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
// Manual export global type
3+
4+
export {};
5+
6+
declare global {
7+
8+
const t: typeof import('i18next').default['t'];
9+
10+
// ---------------------------Component-------------------------------------
11+
const cls: typeof import('classnames');
12+
}
13+

src/@types/i18next.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { resources } from '../i18n/config';
2+
3+
declare module 'i18next' {
4+
interface CustomTypeOptions {
5+
resources: typeof resources['en'];
6+
}
7+
}

src/App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { changeLanguage } from 'i18next'
2+
3+
export const App = () => {
4+
const changeLang = (lang: 'km' | 'en', forceReload = true) => {
5+
changeLanguage(lang)
6+
forceReload && location.reload()
7+
}
8+
9+
return (
10+
<>
11+
<h1>{t('title', { name: 'Jonh' })}</h1>
12+
<button onClick={() => changeLang('km')}>Change To Khmer</button>
13+
<button onClick={() => changeLang('en')}>Change to English</button>
14+
</>
15+
)
16+
}

src/declarations.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '*.png'
2+
declare module '*.svg' {
3+
const content: string
4+
export default content
5+
}

src/i18n/config.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import i18next from 'i18next'
2+
import { initReactI18next } from 'react-i18next'
3+
import en from './en/translation.json'
4+
import km from './km/translation.json'
5+
6+
import LanguageDetector from 'i18next-browser-languagedetector'
7+
8+
export const resources = {
9+
en: {
10+
translation: en,
11+
},
12+
km: {
13+
translation: km,
14+
},
15+
}
16+
17+
i18next
18+
// detect user language
19+
// learn more: https://github.com/i18next/i18next-browser-languageDetector
20+
.use(LanguageDetector)
21+
// pass the i18n instance to the react-i18next components.
22+
// Alternative use the I18nextProvider: https://react.i18next.com/components/i18nextprovider
23+
.use(initReactI18next)
24+
// init i18next
25+
// for all options read: https://www.i18next.com/overview/configuration-options
26+
.init({
27+
fallbackLng: 'en',
28+
debug: true,
29+
resources,
30+
interpolation: {
31+
escapeValue: false, // not needed for react as it escapes by default
32+
},
33+
34+
// special options for react-i18next
35+
// learn more: https://react.i18next.com/components/i18next-instance
36+
react: {},
37+
})
38+
39+
export default i18next.t

src/i18n/en/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"title": "Welcome {{name}}, to react using react-i18next fully type-safe",
3+
"description": {
4+
"part1": "This is a simple example.",
5+
"part2": "😉"
6+
}
7+
}

src/i18n/km/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"title": "សូមស្វាគមន៍ {{name}} ដើម្បីប្រតិកម្មដោយប្រើ react-i18next fully type-safe",
3+
"description": {
4+
"part1": "នេះគឺជាឧទាហរណ៍ដ៏សាមញ្ញមួយ។",
5+
"part2": "😉"
6+
}
7+
}

src/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>React TypeScript Webpack 5 Starter Template</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
</body>
12+
</html>

src/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ReactDOM from 'react-dom'
2+
import { App } from './App'
3+
import './i18n/config';
4+
5+
ReactDOM.render(<App />, document.getElementById('root'))

tsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
4+
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
5+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ /* Type declaration files to be included in compilation. */,
6+
"lib": [
7+
"DOM",
8+
"ESNext"
9+
] /* Specify library files to be included in the compilation. */,
10+
"jsx": "react-jsx" /* Specify JSX code generation: 'preserve', 'react-native', 'react' or 'react-jsx'. */,
11+
"noEmit": true /* Do not emit outputs. */,
12+
"isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
13+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
14+
"strict": true /* Enable all strict type-checking options. */,
15+
"skipLibCheck": true /* Skip type checking of declaration files. */,
16+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
17+
"resolveJsonModule": true
18+
// "allowJs": true /* Allow javascript files to be compiled. Useful when migrating JS to TS */,
19+
// "checkJs": true /* Report errors in .js files. Works in tandem with allowJs. */,
20+
},
21+
"include": ["src/**/*"]
22+
}

webpack/webpack.common.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const path = require('path')
2+
const webpack = require('webpack')
3+
4+
const HtmlWebpackPlugin = require('html-webpack-plugin')
5+
6+
module.exports = {
7+
entry: path.resolve(__dirname, '..', './src/index.tsx'),
8+
resolve: {
9+
extensions: ['.tsx', '.ts', '.js'],
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.(ts|js)x?$/,
15+
exclude: /node_modules/,
16+
use: [
17+
{
18+
loader: 'babel-loader',
19+
},
20+
],
21+
},
22+
{
23+
test: /\.css$/,
24+
use: ['style-loader', 'css-loader'],
25+
},
26+
{
27+
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
28+
type: 'asset/resource',
29+
},
30+
{
31+
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
32+
type: 'asset/inline',
33+
},
34+
],
35+
},
36+
output: {
37+
path: path.resolve(__dirname, '..', './build'),
38+
filename: 'bundle.js',
39+
},
40+
plugins: [
41+
new HtmlWebpackPlugin({
42+
template: path.resolve(__dirname, '..', './src/index.html'),
43+
}),
44+
new webpack.ProvidePlugin({
45+
t: [require.resolve('../src/i18n/config.ts'), 'default'],
46+
}),
47+
],
48+
stats: 'errors-only',
49+
}

webpack/webpack.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { merge } = require('webpack-merge')
2+
const commonConfig = require('./webpack.common.js')
3+
4+
module.exports = (envVars) => {
5+
const { env } = envVars
6+
const envConfig = require(`./webpack.${env}.js`)
7+
const config = merge(commonConfig, envConfig)
8+
return config
9+
}

webpack/webpack.dev.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const webpack = require('webpack')
2+
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
3+
4+
module.exports = {
5+
mode: 'development',
6+
devtool: 'cheap-module-source-map',
7+
devServer: {
8+
hot: true,
9+
open: true,
10+
},
11+
plugins: [
12+
new ReactRefreshWebpackPlugin(),
13+
new webpack.DefinePlugin({
14+
'process.env.name': JSON.stringify('Vishwas'),
15+
}),
16+
17+
],
18+
}

0 commit comments

Comments
 (0)