Project that testing react possibilities, optimization methods and different js-libraries.
- Node.js
To install environment:
npm i
To start project with webpack in dev mode:
npm run start:dev
To start project with vite in dev mode:
npm run start:dev:vite
npm run start
- launch frontend in dev mode with webpacknpm run start:vite
- launch frontend in dev mode with vitenpm run start:dev
- launch frontend and backend in dev mode with webpacknpm run start:dev:vite
- launch frontend and backend in dev mode with vitenpm run start:dev:server
- launch backend servernpm run build:prod
- start assembling of production buildnpm run build:dev
- start assembling of development buildnpm run lint:ts
- start eslint check of the typescript filesnpm run lint:ts:fix
- start eslint check of the typescript files and fix errorsnpm run lint:scss
- start stylelint check of scss filesnpm run lint:scss:fix
- start stylelint check of scss files and fix errorsnpm run test:unit
- start unit tests with jestnpm run test:ui
- start screenshot tests with loki and storybooknpm run test:ui:update
- add new reference screenshotsnpm run test:ui:ci
- start screenshot tests in CI modenpm run test:ui:report
- make html report of the screenshot tests errorsnpm run test:ui:json
- make json report of the screenshot tests errorsnpm run test:ui:html
- make html report of the screenshot tests errors from json reportnpm run storybook
- launch storybooknpm run storybook:build
- start assembling storybook buildnpm run prepare
- start precommit hooks with huskynpm run generate:slice <layer> <sliceName>
- generate FSD slice
Feature sliced design is used in the project. Link for the documentation
To handle with different translations i18next library is used. Translation files stored at public/locales. Link for the i18next documentation
Tests that are used in the project:
npm run test:unit
- unit tests with jest and React testing librarynpm run test:ui
- screenshot tests with loki and storybook
About tests - Documentation
Linting in project represented with eslint for typescript and stylelint for scss.
To control FSD rules custom eslint-plugin-fish-triangle-eslint-plugin is installed. It contains 3 rules:
- dependency-path-checker - forbid absolute import inside same module
- layer-imports - check layers delegation
- public-api-imports - check absolute imports for importing from public API
npm run lint:ts
- start eslint check of the typescript filesnpm run lint:ts:fix
- start eslint check of the typescript files and fix errorsnpm run lint:scss
- start stylelint check of scss filesnpm run lint:scss:fix
- start stylelint check of scss files and fix errors
For most ui components there are Storybook cases(stories). Server requests are mocked with storybook-addon-mock. Story files(.stories.tsx) are located same folder with ui tsx file.
npm run storybook
- launch storybook
About Storybook.
Example of story:
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { CountrySelect } from './CountrySelect';
export default {
title: 'entities/CountrySelect',
component: CountrySelect,
argTypes: {
backgroundColor: { control: 'color' },
},
args: {
to: '/',
children: 'CurrencySelect',
},
} as ComponentMeta<typeof CountrySelect>;
const Template: ComponentStory<typeof CountrySelect> = (args) => (
<CountrySelect {...args} />
);
export const Primary = Template.bind({});
Primary.args = {};
There are 2 build configs for the project:
- Webpack: ./webpack.config.ts and ./config/build
- Vite: ./vite.config.ts
Main config settings are at ./config:
- /config/babel - babel
- /config/build - webpack
- /config/jest - for jest tests
- /config/storybook - storybook
At scripts folder there are several scripts for code refactoring and generation reports.
- Create slice - generate FSD slice.
- Generate visual json report - make html report of the screenshot tests errors from json report.
- Create public API for shared/ui.
- Update imports - add @ alias for absolute imports.
- Remove feature flags by name and state.
GitHub actions config is at ./.github/workflows. There are actions for linting, testing, build storybook.
Additional precommit hooks are made with husky and its config is ./.husky
The state manager for the project is Redux toolkit. Entities should be normalized with EntityAdapter.
Server requests are made with RTK query.
Also, there is async reducers attaching - DynamicModuleLoader
Feature-flags are allowed only with helper toggleFeatures, with options:
{ name: feature-flag name on: function that will be solved if feature-flag is on off: function that will be solved if feature-flag is off }
There is the script to remove unused feature-flags: ./scripts/remove-feature.ts that is called with two arguments:
- Feature-flag name.
- Feature state.