Skip to content

Commit

Permalink
feat: add refresh content plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatoVan committed Dec 17, 2023
1 parent f5e913d commit 2ba70dc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
32 changes: 12 additions & 20 deletions config/build/buildLoaders.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import webpack from 'webpack';
import { buildCssLoader } from './loaders/buildCssLoader';
import { BuildOptions } from './types/config';
import { buildBabelLoader } from './loaders/buildBabelLoader';

export function buildLoaders(options: BuildOptions): webpack.RuleSetRule[] {
const {
isDev,
apiUrl,

Check warning on line 9 in config/build/buildLoaders.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

'apiUrl' is assigned a value but never used
project,

Check warning on line 10 in config/build/buildLoaders.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

'project' is assigned a value but never used
port,

Check warning on line 11 in config/build/buildLoaders.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

'port' is assigned a value but never used
mode,

Check warning on line 12 in config/build/buildLoaders.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

'mode' is assigned a value but never used
paths,

Check warning on line 13 in config/build/buildLoaders.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

'paths' is assigned a value but never used
} = options;

export function buildLoaders({ isDev }: BuildOptions): webpack.RuleSetRule[] {
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 = buildBabelLoader(options);

Check warning on line 21 in config/build/buildLoaders.ts

View workflow job for this annotation

GitHub Actions / pipeline (17.x)

'babelLoader' is assigned a value but never used

const cssLoader = buildCssLoader(isDev);

Expand Down
2 changes: 2 additions & 0 deletions config/build/buildPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import HtmlWebpackPlugin from 'html-webpack-plugin';
import webpack from 'webpack';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import { BuildOptions } from './types/config';

export function buildPlugins({
Expand All @@ -24,6 +25,7 @@ export function buildPlugins({
];

if (isDev) {
plugins.push(new ReactRefreshWebpackPlugin());
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new BundleAnalyzerPlugin({
openAnalyzer: false,
Expand Down
24 changes: 24 additions & 0 deletions config/build/loaders/buildBabelLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { BuildOptions } from '../types/config';

export function buildBabelLoader({ isDev }: BuildOptions) {
return {
test: /\.(js|jsx|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
[
'i18next-extract',
{
locales: ['ru', 'en'],
keyAsDefaultValue: true,
},
],
isDev && require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
};
}
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-essentials": "^6.4.19",
"@storybook/addon-interactions": "^6.4.19",
Expand Down

0 comments on commit 2ba70dc

Please sign in to comment.