Files
mcb-platform-monorepo/packages/webpack-config/src/config/webpack/setPlugins.ts
T
2025-06-17 11:01:37 +03:00

56 lines
1.6 KiB
TypeScript

/* eslint-disable @typescript-eslint/ban-ts-comment */
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import Dotenv from 'dotenv-webpack';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import type { IPluginOptions } from 'types';
import { ProgressPlugin } from 'webpack';
import type { Configuration } from 'webpack';
import path from 'node:path';
import { setModuleFederationPlugin } from './setModuleFederationPlugin';
/**
* Установка плагинов.
*/
export const setPlugins = ({
isDevelopmentMode,
isProductionMode,
moduleName,
publicPath,
moduleFederationOptions,
}: IPluginOptions): Configuration['plugins'] => {
const dotenvFilename = isProductionMode ? '.env.production' : '.env.development';
const plugins = [
new Dotenv({
path: dotenvFilename,
}),
new HtmlWebpackPlugin({
template: path.resolve(publicPath, 'index.html'),
filename: 'index.html',
favicon: path.resolve(publicPath, 'favicon.ico'),
hash: true,
cache: true,
}),
setModuleFederationPlugin({ moduleName, moduleFederationOptions }),
];
if (isDevelopmentMode) {
plugins.push(
new ProgressPlugin(),
// Выносит проверку типов в отдельный процесс
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
},
}),
new ReactRefreshWebpackPlugin()
);
}
// @ts-ignore
return plugins;
};