npx create-react-app my-app —-typescript
npm i -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
npx eslint —init
npm i -D eslint-config-standard eslint-plugin-import eslint-plugin-jest eslint-plugin-node eslint-plugin-promise eslint-plugin-react eslint-plugin-standard
{
"env": {
"browser": true,
"es6": true
},
"parser": "@typescript-eslint/parser",
"extends": [
"standard",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:jest/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"react": {
"version": "latest"
}
},
"rules": {
"@typescript-eslint/indent": "off",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"jsx-quotes": ["error", "prefer-single"]
}
}
npx eslint src/*.tsx
npm i -D prettier-eslint prettier-eslint-cli eslint-config-prettier eslint-plugin-prettier
{
"extends": ["plugin:prettier/recommended"]
}
mkdir .vscode
touch .vscode/settings.json
{
"editor.formatOnSave": true,
"prettier.singleQuote": true
}
touch .eslintignore
dist
node_modules
touch .prettierrc
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true
}
"scripts": {
"lint": "eslint '**/*.{js,ts,tsx}'",
"lint:fix": "npm run lint -- --fix"
}
npm run lint
npm run lint:fix
npm i -D husky lint-staged
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts,tsx}": [
"npm run lint:fix",
"git add"
]
},
touch tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"target": "es5",
// "lib": ["dom", "dom.iterable", "esnext"],
// "allowJs": true,
// "skipLibCheck": true,
"esModuleInterop": true,
// "allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
// "resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"noImplicitAny": true,
"sourceMap": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
touch .babelrc
npm i -D babel-loader @babel/core @babel/preset-env @babel/preset-react @babel/preset-typescript
{
"presets": [
"@babel/typescript",
[
"@babel/env",
{
"targets": "node 10"
}
],
"@babel/react"
],
"env": {
"esm": {
"presets": [
"@babel/typescript",
[
"@babel/env",
{
"modules": false
}
],
"@babel/react"
]
}
}
}
npm i -D webpack webpack-cli webpack-dev-server html-webpack-plugin css-loader file-loader html-loader style-loader ts-loader
touch webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.tsx',
output: {
path: path.join(__dirname, '/dist'),
filename: 'bundle.js'
},
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.html$/,
use: 'html-loader'
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ['file-loader']
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, '/src/index.html'),
filename: './index.html'
})
],
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 3000
}
};
// "main": "index.js",
"private": true,
"scripts": {
"start": "webpack-dev-server --mode development --open",
"build": "webpack --mode production",
}
npm start
npm run build