Skip to content

Commit 780f0ec

Browse files
committed
refactor(type): improve type definitions for rspack config
1 parent ae6a338 commit 780f0ec

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

rspack.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
12
import path from 'path';
2-
import { Configuration } from '@rspack/cli';
3+
import type { Configuration } from '@rspack/cli';
34
import * as rspack from '@rspack/core';
45
import type { SwcLoaderOptions } from '@rspack/core';
56
import { WebpackSweetEntry } from '@sect/webpack-sweet-entry';
@@ -11,6 +12,7 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
1112
import notifier from 'node-notifier';
1213
import StyleLintPlugin from 'stylelint-webpack-plugin';
1314
// import SVGSpritemapPlugin from 'svg-spritemap-webpack-plugin';
15+
import type { WebpackError } from 'webpack/types';
1416
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
1517
import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts';
1618

@@ -112,7 +114,7 @@ const getJSPlugins = () => {
112114

113115
plugins.push(
114116
new NotifierPlugin({
115-
onErrors: (severity: string, errors: any[]) => {
117+
onErrors: (severity: string, errors: WebpackError[]) => {
116118
if (severity !== 'error') return;
117119
const error = errors[0];
118120
notifier.notify({
@@ -149,7 +151,7 @@ const getCSSPlugins = () => {
149151

150152
plugins.push(
151153
new NotifierPlugin({
152-
onErrors: (severity: string, errors: any[]) => {
154+
onErrors: (severity: string, errors: WebpackError[]) => {
153155
if (severity !== 'error') return;
154156
const error = errors[0];
155157
notifier.notify({
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
declare module '@soda/friendly-errors-webpack-plugin';
1+
import type { Compiler, WebpackError } from 'webpack';
2+
// eslint-disable-next-line import/no-extraneous-dependencies
3+
import { Plugin } from 'webpack';
4+
5+
declare class FriendlyErrorsWebpackPlugin extends Plugin {
6+
constructor(options?: FriendlyErrorsWebpackPlugin.Options);
7+
apply(compiler: Compiler): void;
8+
}
9+
10+
declare namespace FriendlyErrorsWebpackPlugin {
11+
type Severity = 'error' | 'warning';
12+
13+
interface Options {
14+
compilationSuccessInfo?: {
15+
messages: string[];
16+
notes: string[];
17+
};
18+
onErrors?: (severity: Severity, errors: WebpackError[]) => void;
19+
clearConsole?: boolean;
20+
additionalFormatters?: Array<
21+
(errors: WebpackError[], type: Severity) => string[]
22+
>;
23+
additionalTransformers?: Array<(error: WebpackError) => WebpackError>;
24+
}
25+
}
26+
27+
export = FriendlyErrorsWebpackPlugin;

0 commit comments

Comments
 (0)