88import path , { extname } from 'node:path' ;
99import type { Rspack } from '@rsbuild/core' ;
1010
11- export const BASE_URI = " webpack://" ;
12- export const MODULE_TYPE = " css/mini-extract" ;
13- export const AUTO_PUBLIC_PATH = " __mini_css_extract_plugin_public_path_auto__" ;
11+ export const BASE_URI = ' webpack://' ;
12+ export const MODULE_TYPE = ' css/mini-extract' ;
13+ export const AUTO_PUBLIC_PATH = ' __mini_css_extract_plugin_public_path_auto__' ;
1414export const ABSOLUTE_PUBLIC_PATH : string = `${ BASE_URI } /mini-css-extract-plugin/` ;
1515export const SINGLE_DOT_PATH_SEGMENT =
16- " __mini_css_extract_plugin_single_dot_path_segment__" ;
16+ ' __mini_css_extract_plugin_single_dot_path_segment__' ;
1717
1818interface DependencyDescription {
1919 identifier : string ;
@@ -28,9 +28,7 @@ interface DependencyDescription {
2828}
2929
3030// https://github.com/web-infra-dev/rspack/blob/c0986d39b7d647682f10fcef5bbade39fd016eca/packages/rspack/src/config/types.ts#L10
31- type Filename =
32- | string
33- | ( ( pathData : any , assetInfo ?: any ) => string ) ;
31+ type Filename = string | ( ( pathData : any , assetInfo ?: any ) => string ) ;
3432
3533export interface CssExtractRspackLoaderOptions {
3634 publicPath ?: string | ( ( resourcePath : string , context : string ) => string ) ;
@@ -92,32 +90,31 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
9290
9391 let { publicPath } = this . _compilation ! . outputOptions ;
9492
93+ if ( typeof options . publicPath === 'string' ) {
94+ // eslint-disable-next-line prefer-destructuring
95+ publicPath = options . publicPath ;
96+ } else if ( typeof options . publicPath === 'function' ) {
97+ publicPath = options . publicPath ( this . resourcePath , this . rootContext ) ;
98+ }
9599
96- if ( typeof options . publicPath === "string" ) {
97- // eslint-disable-next-line prefer-destructuring
98- publicPath = options . publicPath ;
99- } else if ( typeof options . publicPath === "function" ) {
100- publicPath = options . publicPath ( this . resourcePath , this . rootContext ) ;
101- }
102-
103- if ( publicPath === "auto" ) {
104- publicPath = AUTO_PUBLIC_PATH ;
105- }
100+ if ( publicPath === 'auto' ) {
101+ publicPath = AUTO_PUBLIC_PATH ;
102+ }
106103
107- let publicPathForExtract : Filename | undefined ;
104+ let publicPathForExtract : Filename | undefined ;
108105
109- if ( typeof publicPath === " string" ) {
110- const isAbsolutePublicPath = / ^ [ a - z A - Z ] [ a - z A - Z \d + \- . ] * ?: / . test ( publicPath ) ;
106+ if ( typeof publicPath === ' string' ) {
107+ const isAbsolutePublicPath = / ^ [ a - z A - Z ] [ a - z A - Z \d + \- . ] * ?: / . test ( publicPath ) ;
111108
112- publicPathForExtract = isAbsolutePublicPath
113- ? publicPath
114- : `${ ABSOLUTE_PUBLIC_PATH } ${ publicPath . replace (
115- / \. / g,
116- SINGLE_DOT_PATH_SEGMENT
117- ) } `;
118- } else {
119- publicPathForExtract = publicPath ;
120- }
109+ publicPathForExtract = isAbsolutePublicPath
110+ ? publicPath
111+ : `${ ABSOLUTE_PUBLIC_PATH } ${ publicPath . replace (
112+ / \. / g,
113+ SINGLE_DOT_PATH_SEGMENT ,
114+ ) } `;
115+ } else {
116+ publicPathForExtract = publicPath ;
117+ }
121118
122119 const handleExports = (
123120 originalExports :
0 commit comments