8000 GitHub - quoctruongdev/react-typescript-webpack: React-Typescript-Webpack was config with React, Typescript, and Webpack without CRA. Faster to start your next react project.
[go: up one dir, main page]

Skip to content

React-Typescript-Webpack was config with React, Typescript, and Webpack without CRA. Faster to start your next react project.

License

Notifications You must be signed in to change notification settings

quoctruongdev/react-typescript-webpack

 
 

Repository files navigation

react typescript webpack starter

Start your react typescript project with manual webpack config in seconds

Flexible to control webpack, easy to deploy
Keywords: React Starter, Webpack, Typescript, React.js, Redux, Babel, jest, react-router, sass, redux-thunk, pm2

Created with by 👻 Aldenn


Overview

React-Typescript-Webpack was config with React, Typescript and Webpack without CRA. Faster to start your next react project.


Quick Start

For Development:

  1. Clone this repo to your local machine using:

    git clone git@github.com:thaind97git/react-typescript-webpack.git
  2. Change the current working directory to the project:

    cd react-typescript-webpack
  3. Install dependencies:

    [ yarn or npm install ]
  4. At this point you can run npm run dev or yarn dev to run project with development mode

    Now, your browser will auto open at http://127.0.0.1:3000

For Production:

  1. Run command to build:

    [ yarn or npm run ] build
  2. Setup env for production mode by create new file .env.production

  3. Run project at build directory

    • Using pm2: [ yarn or npm run ] start-pm2
    • Run with terminal: [ yarn or npm run ] start

Features

  • React hook
  • Webpack 5
  • Typescript
  • Sass
  • Redux-thunk
  • Redux-saga
  • Jest
  • Axios
  • I18n [Not completed]
  • React-router
  • Alias
  • Hot reload
  • Eslint
  • Prettier and Husky

How to using

  • Router:

    • Create new feature at src/features/<feature-name/>

    • Create a route.ts inside src/features/<feature-name/> and export default an array match with rules:

      import { lazy } from 'react';
      const Component = lazy(() => import('./path-to-component'));
      
      export default [
        {
          /*
           * name of a route
           * using to apply key react when generate routes
           * required for declare
           */
          name: 'name',
          /*
           * path of route
           */
          path: '/path-name',
          /*
           * using as exact in react-router
           */
          exact: true,
          /*
           * dynamic render layout for each route
           * header: false -> route will auto hide header
           * if this rendered, don't need to declare
           * control this inside `src/store/slices/layoutSlice` with more section
           */
          layout: {
            header: false,
            footer: false,
          },
          /*
           * component rendered inside route
           */
          component: Component,
        },
      ];

      - You don't need do anything else after create and modify route.ts because i'm using import-glob to auto import (check at webpack/webpack.common.js for plugin, src/router/index.ts and src/layouts/main/index.tsx for using).

      - If you don't want to use auto import or using project with jest, just using the code that i'm commented. Because i'm not yet support auto import for jest.

  • Write new component

    • Create new folder at src/components/<component-name/>

    • Create an index.tsx and <any-name>.scss

      - Don't need import scss into component, It will already merged into App.scss after you restart server.

      - This is a feature by using import-glob (check at webpack/webpack.common.js for plugin and src/styles/App.scss for using)

      - You should use BEM to write css without conflict


Tips

  • Go to .huskyinstall, remove comment at line 37 and run [yarn or npm install] again to apply run test when using git push origin [ branch ]
  • Go to config/@types/[any-file-name].d.ts to declare global type of typescript
  • Go to pm2/prod.json and change "name: react-webpack-typescript-starter ->[other-name]" to config pm2 app name
  • Go to components/spinner/index.tsx and modify jsx + css to use another loading

Carefully

  • Don't create folder with the PascalCase. Because it will throw error when build prod at ubuntu. I will fix it later or happy if you have a PR to fix it.
    Module not found: Error: Can't resolve '@/path-to-pascal-case' in '/path-to-lower-case'

Other References

License

This project is licensed under the MIT license, Copyright (c) 2021 Aldenn. For more information see LICENSE.md.

About

React-Typescript-Webpack was config with React, Typescript, and Webpack without CRA. Faster to start your next react project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 44.4%
  • SCSS 28.8%
  • JavaScript 26.4%
  • HTML 0.4%
0