Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions config/build/buildDevServer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';

Check failure on line 1 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
import { BuildOptions } from './types/config';

Check failure on line 2 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'

Check failure on line 3 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
export function buildDevServer(options: BuildOptions): DevServerConfiguration {

Check failure on line 4 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
return {
port: options.port,
open: true,
historyApiFallback: true,
hot: true,
};
return {

Check failure on line 5 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
port: options.port,

Check failure on line 6 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
open: true,

Check failure on line 7 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
historyApiFallback: true,

Check failure on line 8 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
hot: true,

Check failure on line 9 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
};

Check failure on line 10 in config/build/buildDevServer.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

Expected linebreaks to be 'CRLF' but found 'LF'
}
88 changes: 44 additions & 44 deletions config/build/buildLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,54 @@ import { buildCssLoader } from './loaders/buildCssLoader';
import { BuildOptions } from './types/config';

export function buildLoaders({ isDev }: BuildOptions): webpack.RuleSetRule[] {
const svgLoader = {
test: /\.svg$/,
use: ['@svgr/webpack'],
};
const svgLoader = {
test: /\.svg$/,
use: ['@svgr/webpack'],
};

const babelLoader = {
test: /\.(js|jsx|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
[
'i18next-extract',
{
locales: ['ru', 'en'],
keyAsDefaultValue: true,
},
],
],
const babelLoader = {
test: /\.(js|jsx|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
[
'i18next-extract',
{
locales: ['ru', 'en'],
keyAsDefaultValue: true,
},
},
};
],
],
},
},
};

const cssLoader = buildCssLoader(isDev);
const cssLoader = buildCssLoader(isDev);

// Если не используем тайпскрипт - нужен babel-loader
const typescriptLoader = {
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
};
// Если не используем тайпскрипт - нужен babel-loader
const typescriptLoader = {
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
};

const fileLoader = {
test: /\.(png|jpe?g|gif|woff2|woff)$/i,
use: [
{
loader: 'file-loader',
},
],
};
const fileLoader = {
test: /\.(png|jpe?g|gif|woff2|woff)$/i,
use: [
{
loader: 'file-loader',
},
],
};

return [
fileLoader,
svgLoader,
babelLoader,
typescriptLoader,
cssLoader,
];
return [
fileLoader,
svgLoader,
babelLoader,
typescriptLoader,
cssLoader,
];
}
40 changes: 20 additions & 20 deletions config/build/buildPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import { BuildOptions } from './types/config';

export function buildPlugins({ paths, isDev }: BuildOptions): webpack.WebpackPluginInstance[] {
const plugins = [
new HtmlWebpackPlugin({
template: paths.html,
}),
new webpack.ProgressPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:8].css',
chunkFilename: 'css/[name].[contenthash:8].css',
}),
new webpack.DefinePlugin({
__IS_DEV__: JSON.stringify(isDev),
}),
];
const plugins = [
new HtmlWebpackPlugin({
template: paths.html,
}),
new webpack.ProgressPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:8].css',
chunkFilename: 'css/[name].[contenthash:8].css',
}),
new webpack.DefinePlugin({
__IS_DEV__: JSON.stringify(isDev),
}),
];

if (isDev) {
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new BundleAnalyzerPlugin({
openAnalyzer: false,
}));
}
if (isDev) {
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new BundleAnalyzerPlugin({
openAnalyzer: false,
}));
}

return plugins;
return plugins;
}
14 changes: 7 additions & 7 deletions config/build/buildResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { ResolveOptions } from 'webpack';
import { BuildOptions } from './types/config';

export function buildResolvers(options: BuildOptions): ResolveOptions {
return {
extensions: ['.tsx', '.ts', '.js'],
preferAbsolute: true,
modules: [options.paths.src, 'node_modules'],
mainFiles: ['index'],
alias: {},
};
return {
extensions: ['.tsx', '.ts', '.js'],
preferAbsolute: true,
modules: [options.paths.src, 'node_modules'],
mainFiles: ['index'],
alias: {},
};
}
34 changes: 17 additions & 17 deletions config/build/buildWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { buildResolvers } from './buildResolvers';
import { BuildOptions } from './types/config';

export function buildWebpackConfig(options: BuildOptions): webpack.Configuration {
const { paths, mode, isDev } = options;
const { paths, mode, isDev } = options;

return {
mode,
entry: paths.entry,
output: {
filename: '[name].[contenthash].js',
path: paths.build,
clean: true,
},
plugins: buildPlugins(options),
module: {
rules: buildLoaders(options),
},
resolve: buildResolvers(options),
devtool: isDev ? 'inline-source-map' : undefined,
devServer: isDev ? buildDevServer(options) : undefined,
};
return {
mode,
entry: paths.entry,
output: {
filename: '[name].[contenthash].js',
path: paths.build,
clean: true,
},
plugins: buildPlugins(options),
module: {
rules: buildLoaders(options),
},
resolve: buildResolvers(options),
devtool: isDev ? 'inline-source-map' : undefined,
devServer: isDev ? buildDevServer(options) : undefined,
};
}
36 changes: 18 additions & 18 deletions config/build/loaders/buildCssLoader.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import MiniCssExtractPlugin from 'mini-css-extract-plugin';

export function buildCssLoader(isDev: boolean) {
return {
test: /\.s[ac]ss$/i,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
auto: (resPath: string) => Boolean(resPath.includes('.module.')),
localIdentName: isDev
? '[path][name]__[local]--[hash:base64:5]'
: '[hash:base64:8]',
},
},
},
'sass-loader',
],
};
return {
test: /\.s[ac]ss$/i,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
auto: (resPath: string) => Boolean(resPath.includes('.module.')),
localIdentName: isDev
? '[path][name]__[local]--[hash:base64:5]'
: '[hash:base64:8]',
},
},
},
'sass-loader',
],
};
}
42 changes: 21 additions & 21 deletions config/storybook/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import { buildCssLoader } from '../build/loaders/buildCssLoader';
import { BuildPaths } from '../build/types/config';

export default ({ config }: {config: webpack.Configuration}) => {
const paths: BuildPaths = {
build: '',
html: '',
entry: '',
src: path.resolve(__dirname, '..', '..', 'src'),
};
config.resolve.modules.push(paths.src);
config.resolve.extensions.push('.ts', '.tsx');
const paths: BuildPaths = {
build: '',
html: '',
entry: '',
src: path.resolve(__dirname, '..', '..', 'src'),
};
config.resolve.modules.push(paths.src);
config.resolve.extensions.push('.ts', '.tsx');

// eslint-disable-next-line no-param-reassign
config.module.rules = config.module.rules.map((rule: RuleSetRule) => {
if (/svg/.test(rule.test as string)) {
return { ...rule, exclude: /\.svg$/i };
}
// eslint-disable-next-line no-param-reassign
config.module.rules = config.module.rules.map((rule: RuleSetRule) => {
if (/svg/.test(rule.test as string)) {
return { ...rule, exclude: /\.svg$/i };
}

return rule;
});
return rule;
});

config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
config.module.rules.push(buildCssLoader(true));
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
config.module.rules.push(buildCssLoader(true));

return config;
return config;
};
4 changes: 2 additions & 2 deletions src/app/providers/ErrorBoundary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import ErrorBoundary from './ui/ErrorBoundary';
import { BugButton } from './ui/BugButton';

export {
ErrorBoundary,
BugButton,
ErrorBoundary,
BugButton,
};
30 changes: 15 additions & 15 deletions src/app/providers/ErrorBoundary/ui/BugButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { useTranslation } from 'react-i18next';

// Компонент для тестирования ErrorBoundary
export const BugButton = () => {
const [error, setError] = useState(false);
const { t } = useTranslation();
const [error, setError] = useState(false);
const { t } = useTranslation();

const onThrow = () => setError(true);
const onThrow = () => setError(true);

useEffect(() => {
if (error) {
throw new Error();
}
}, [error]);
useEffect(() => {
if (error) {
throw new Error();
}
}, [error]);

return (
<Button
onClick={onThrow}
>
{t('throw error')}
</Button>
);
return (
<Button
onClick={onThrow}
>
{t('throw error')}
</Button>
);
};
Loading
Loading