build: reduce bundle size

refactor dependencies imports to reduce bundle size
This commit is contained in:
Chika 2021-04-27 11:37:12 +03:00
parent aa59a7813a
commit 204f9c077d
14 changed files with 63 additions and 68 deletions

View File

@ -1,20 +1,31 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const CracoLessPlugin = require('craco-less');
const CracoAntDesignPlugin = require('craco-antd');
const colors = require('./src/client/UIKit/colors');
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
plugin: CracoAntDesignPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
modifyVars: { '@primary-color': colors.primary },
javascriptEnabled: true,
customizeTheme: {
'@primary-color': colors.primary,
},
babelPluginImportOptions: {
libraryDirectory: 'es',
},
},
},
],
babel: {
plugins: [
[
'transform-imports',
{
lodash: {
transform: 'lodash/${member}',
preventFullImport: true,
},
},
],
],
},
};

View File

@ -12,10 +12,11 @@
"@testing-library/user-event": "^7.1.2",
"antd": "^4.15.0",
"axios": "^0.21.1",
"craco-less": "^1.17.1",
"babel-plugin-transform-imports": "^2.0.0",
"craco-antd": "^1.19.0",
"dayjs": "^1.10.4",
"graphql": "^15.5.0",
"lodash": "^4.17.21",
"luxon": "^1.26.0",
"mobx": "^6.1.8",
"mobx-react-lite": "^3.2.0",
"pluralize": "^8.0.0",
@ -34,7 +35,6 @@
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/lodash": "^4.14.168",
"@types/luxon": "^1.26.3",
"@types/pluralize": "^0.0.29",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
@ -42,7 +42,8 @@
"@types/rebass": "^4.0.8",
"@types/styled-components": "^5.1.9",
"commitizen": "^4.2.3",
"cz-conventional-changelog": "^3.3.0"
"cz-conventional-changelog": "^3.3.0",
"source-map-explorer": "^2.5.2"
},
"scripts": {
"test": "craco test",
@ -51,7 +52,8 @@
"build": "craco build",
"eslint": "eslint ./src",
"eslint:fix": "eslint ./src --fix",
"commit": "git-cz"
"commit": "git-cz",
"analyze": "source-map-explorer 'build/static/js/*.js'"
},
"eslintConfig": {
"extends": "react-app"

View File

@ -1,5 +1,5 @@
import { Spin } from 'antd';
import { Box, Flex } from 'rebass/styled-components';
import { Box, Flex } from 'client/UIKit/grid';
export default () => (
<Box height="100%" py="10px">

View File

@ -1,4 +1,5 @@
import { DownloadOutlined } from '@ant-design/icons';
import DownloadOutlined from '@ant-design/icons/lib/icons/DownloadOutlined';
import { currentYear } from 'core/tools/date';
import {
validateEmail,
validateInn,
@ -165,7 +166,7 @@ const elementsProps: TElements<ElementProps> = {
},
tbxLeaseObjectYear: {
min: '1994',
max: new Date().getUTCFullYear() + 1,
max: currentYear + 1,
},
selectLeaseObjectCategory: {
showSearch: false,

View File

@ -1,6 +1,6 @@
import { currentDate } from 'core/tools/date';
import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
import { gql } from '@apollo/client';
import { currentISODate } from 'core/tools/date';
import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
const query = gql`
query(
@ -262,7 +262,7 @@ const query = gql`
`;
const variables = {
currentDate,
currentDate: currentISODate,
statecode: 0,
supplier_account_type: [100000001],
supplier_legal_form: 100000001,

View File

@ -1,6 +1,6 @@
import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
import { currentDate } from 'core/tools/date';
import { gql } from '@apollo/client';
import { currentISODate } from 'core/tools/date';
import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
const query = gql`
query($statecode: Int, $currentDate: DateTime) {
@ -61,7 +61,7 @@ const query = gql`
const variables = {
statecode: 0,
currentDate,
currentDate: currentISODate,
};
export default {

View File

@ -1,9 +1,9 @@
import valuesConstants from 'core/constants/values';
import { currentDate } from 'core/tools/date';
import { PaymentRow, PreparedValues } from 'core/types/Calculation/Prepare';
import { IPreparedData } from 'core/types/Calculation/Requests';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { DateTime } from 'luxon';
import { NIL } from 'uuid';
import NIL from 'uuid/dist/esm-browser/nil';
import { convertPrice } from '../../lib/tools';
export default ({
@ -11,8 +11,6 @@ export default ({
}: {
calculationStore: ICalculationStore;
}): IPreparedData => {
const currentDate = DateTime.local().toUTC().toJSDate();
const { values, options, tables } = calculationStore;
const preparedPaymentsRows: PaymentRow[] = Array.from(

View File

@ -1,11 +1,11 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { message } from 'antd';
import { elementsValues } from 'client/Containers/Calculation/lib/elements/values';
import { openNotification } from 'client/Elements/Notification';
import { calculationProcess } from 'client/stores/CalculationStore';
import initialValues from 'client/stores/CalculationStore/config/initialValues';
import CrmService from 'core/services/CrmService';
import { currentDate } from 'core/tools/date';
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { currentISODate } from 'core/tools/date';
import { IGetCRMEntitiesResponse } from 'core/types/Calculation/Responses';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { TElements } from 'core/types/Calculation/Store/elements';
@ -139,7 +139,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
evo_brandid: quote.evo_brandid || NIL,
evo_modelid: quote.evo_modelid || NIL,
salonaccountid: quote.evo_supplier_accountid || NIL,
currentDate,
currentDate: currentISODate,
dealer_person_accountid: quote.evo_dealer_person_accountid || NIL,
dealer_broker_accountid: quote.evo_dealer_broker_accountid || NIL,
hasDealerBroker: quote.evo_dealer_broker_accountid ? true : false,

View File

@ -1,9 +1,9 @@
import { gql } from '@apollo/client';
import CrmService from 'core/services/CrmService';
import { currentDate } from 'core/tools/date';
import { currentISODate } from 'core/tools/date';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { ElementStatus } from 'core/types/statuses';
import { Process } from 'core/types/Calculation/Store/process';
import { ElementStatus } from 'core/types/statuses';
import { quoteFields } from '../lib/queries';
export default [
@ -350,7 +350,7 @@ export default [
`,
variables: {
evo_agent_accountid: indAgentId,
currentDate,
currentDate: currentISODate,
statecode: 0,
},
toOptions: ['evo_reward_condition'],
@ -410,7 +410,7 @@ export default [
`,
variables: {
evo_agent_accountid: doubleAgentId,
currentDate,
currentDate: currentISODate,
statecode: 0,
},
toOptions: ['evo_reward_condition'],
@ -472,7 +472,7 @@ export default [
`,
variables: {
evo_agent_accountid: calcFinDepartmentId,
currentDate,
currentDate: currentISODate,
statecode: 0,
},
toOptions: ['evo_reward_condition'],
@ -532,7 +532,7 @@ export default [
`,
variables: {
evo_agent_accountid: calcBrokerId,
currentDate,
currentDate: currentISODate,
statecode: 0,
},
toOptions: ['evo_reward_condition'],
@ -708,7 +708,7 @@ export default [
`,
variables: {
evo_agent_accountid: dealerBrokerId,
currentDate,
currentDate: currentISODate,
statecode: 0,
},
toOptions: ['evo_reward_condition'],
@ -767,7 +767,7 @@ export default [
`,
variables: {
evo_agent_accountid: dealerPersonId,
currentDate,
currentDate: currentISODate,
statecode: 0,
},
toOptions: ['evo_reward_condition'],

View File

@ -1,4 +1,5 @@
import { TValues, TValue } from 'core/types/Calculation/Store/values';
import { currentYear } from 'core/tools/date';
import { TValue, TValues } from 'core/types/Calculation/Store/values';
const initialValues: TValues<TValue> = {
lead: null,
@ -37,7 +38,7 @@ const initialValues: TValues<TValue> = {
maxMass: 0,
countSeats: 0,
maxSpeed: 0,
leaseObjectYear: new Date().getUTCFullYear(),
leaseObjectYear: currentYear,
engineType: 100000000,
leaseObjectCategory: 100000001,
leaseObjectMotorPower: 0,

View File

@ -1,14 +0,0 @@
function assignProperties(target, ...sources) {
sources.forEach(source => {
Object.defineProperties(
target,
Object.keys(source).reduce((descriptors, key) => {
descriptors[key] = Object.getOwnPropertyDescriptor(source, key);
return descriptors;
}, {})
);
});
return target;
}
export default assignProperties;

View File

@ -1,3 +1,7 @@
import { DateTime } from 'luxon';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
dayjs.extend(utc);
export const currentDate = DateTime.local().toUTC().toISO();
export const currentISODate = dayjs().utc().toISOString();
export const currentDate = dayjs().toDate();
export const currentYear = dayjs().year();

View File

@ -1,9 +0,0 @@
export function stringifyObject(obj_from_json: any): string {
if (typeof obj_from_json !== 'object' || Array.isArray(obj_from_json)) {
return JSON.stringify(obj_from_json);
}
const props = Object.keys(obj_from_json)
.map(key => `${key}:${stringifyObject(obj_from_json[key])}`)
.join(',');
return `${props}`;
}

View File

@ -1,4 +1,5 @@
import validator from 'validator';
import isEmail from 'validator/es/lib/isEmail';
import isMobilePhone from 'validator/es/lib/isMobilePhone';
const isINNIndividual = value => {
const valueToString = value ? value.toString() : '';
@ -81,10 +82,10 @@ export function validateKpp(value) {
export function validatePhone(value) {
const stringValue = value ? value.toString() : '';
return validator.isMobilePhone(stringValue, ['ru-RU']);
return isMobilePhone(stringValue, ['ru-RU']);
}
export function validateEmail(value) {
const stringValue = value ? value.toString() : '';
return validator.isEmail(stringValue);
return isEmail(stringValue);
}