Skip to content

Commit 679cf8f

Browse files
committedJul 25, 2024·
feat(bundler-webpack): normalize loader options type
1 parent f3251b7 commit 679cf8f

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed
 

‎packages/bundler-webpack/src/config/handleModuleStyles.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin'
44
import type Config from 'webpack-5-chain'
55
import type {
66
LessLoaderOptions,
7-
LoaderOptions,
87
SassLoaderOptions,
8+
StylePreprocessorLoaderOptions,
99
StylusLoaderOptions,
1010
WebpackBundlerOptions,
1111
} from '../types.js'
@@ -26,7 +26,9 @@ export const handleModuleStyles = ({
2626
isBuild: boolean
2727
isServer: boolean
2828
}): void => {
29-
const handleStyle = <T extends LoaderOptions = LoaderOptions>({
29+
const handleStyle = <
30+
T extends StylePreprocessorLoaderOptions = StylePreprocessorLoaderOptions,
31+
>({
3032
lang,
3133
test,
3234
loaderName,

‎packages/bundler-webpack/src/types.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ export interface WebpackBundlerOptions {
7777
}
7878

7979
/**
80-
* Common options for some webpack loaders
80+
* Common options for style preprocessor webpack loaders
8181
*/
82-
export interface LoaderOptions {
83-
sourceMap?: boolean
84-
webpackImporter?: boolean
82+
export interface StylePreprocessorLoaderOptions {
8583
additionalData?:
8684
| string
8785
| ((
8886
content: string,
8987
loaderContext: LoaderContext<Record<string, any>>,
9088
) => string)
89+
sourceMap?: boolean
90+
webpackImporter?: boolean
9191
}
9292

9393
/**
@@ -102,18 +102,20 @@ export type StylePreprocessorOptions<
102102
*
103103
* @see https://github.com/webpack-contrib/postcss-loader#options
104104
*/
105-
export interface PostcssLoaderOptions extends Pick<LoaderOptions, 'sourceMap'> {
105+
export interface PostcssLoaderOptions
106+
extends Pick<StylePreprocessorLoaderOptions, 'sourceMap'> {
106107
execute?: boolean
107-
postcssOptions?: StylePreprocessorOptions
108108
implementation?: ((...args: any) => any) | string
109+
postcssOptions?: StylePreprocessorOptions
109110
}
110111

111112
/**
112113
* Options for stylus-loader
113114
*
114115
* @see https://github.com/webpack-contrib/stylus-loader#options
115116
*/
116-
export interface StylusLoaderOptions extends LoaderOptions {
117+
export interface StylusLoaderOptions extends StylePreprocessorLoaderOptions {
118+
implementation?: ((...args: any) => any) | string
117119
stylusOptions?: StylePreprocessorOptions
118120
}
119121

@@ -122,17 +124,20 @@ export interface StylusLoaderOptions extends LoaderOptions {
122124
*
123125
* @see https://github.com/webpack-contrib/sass-loader#options
124126
*/
125-
export interface SassLoaderOptions extends LoaderOptions {
127+
export interface SassLoaderOptions extends StylePreprocessorLoaderOptions {
126128
api?: 'legacy' | 'modern' | 'modern-compiler'
127129
implementation?: Record<string, any> | string
128130
sassOptions?: StylePreprocessorOptions
131+
warnRuleAsWarning?: boolean
129132
}
130133

131134
/**
132135
* Options for less-loader
133136
*
134137
* @see https://github.com/webpack-contrib/less-loader#options
135138
*/
136-
export interface LessLoaderOptions extends LoaderOptions {
139+
export interface LessLoaderOptions extends StylePreprocessorLoaderOptions {
140+
implementation?: Record<string, any> | string
141+
lessLogAsWarnOrErr?: boolean
137142
lessOptions?: StylePreprocessorOptions
138143
}

0 commit comments

Comments
 (0)
Please sign in to comment.