@@ -137,7 +137,7 @@ export function getBabelOptions({
137137
138138// Name is generic on purpose
139139// we want to support multiple js loader implementations (babel + esbuild)
140- export function getJSLoader ( {
140+ function getDefaultBabelLoader ( {
141141 isServer,
142142 babelOptions,
143143} : {
@@ -150,6 +150,19 @@ export function getJSLoader({
150150 } ;
151151}
152152
153+ export const getCustomizableJSLoader = (
154+ jsLoader : 'babel' | ( ( isServer : boolean ) => RuleSetRule ) = 'babel' ,
155+ ) => ( {
156+ isServer,
157+ babelOptions,
158+ } : {
159+ isServer : boolean ;
160+ babelOptions ?: TransformOptions | string ;
161+ } ) : RuleSetRule =>
162+ jsLoader === 'babel'
163+ ? getDefaultBabelLoader ( { isServer, babelOptions} )
164+ : jsLoader ( isServer ) ;
165+
153166// TODO remove this before end of 2021?
154167const warnBabelLoaderOnce = memoize ( function ( ) {
155168 console . warn (
@@ -163,7 +176,7 @@ const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(
163176 babelOptions ?: TransformOptions | string ,
164177) {
165178 warnBabelLoaderOnce ( ) ;
166- return getJSLoader ( { isServer, babelOptions} ) ;
179+ return getDefaultBabelLoader ( { isServer, babelOptions} ) ;
167180} ;
168181
169182// TODO remove this before end of 2021 ?
@@ -184,17 +197,19 @@ function getCacheLoaderDeprecated() {
184197 * @param configureWebpack a webpack config or a function to modify config
185198 * @param config initial webpack config
186199 * @param isServer indicates if this is a server webpack configuration
200+ * @param jsLoader custom js loader config
187201 * @returns final/ modified webpack config
188202 */
189203export function applyConfigureWebpack (
190204 configureWebpack : ConfigureWebpackFn ,
191205 config : Configuration ,
192206 isServer : boolean ,
207+ jsLoader ?: 'babel' | ( ( isServer : boolean ) => RuleSetRule ) ,
193208) : Configuration {
194209 // Export some utility functions
195210 const utils : ConfigureWebpackUtils = {
196211 getStyleLoaders,
197- getJSLoader,
212+ getJSLoader : getCustomizableJSLoader ( jsLoader ) ,
198213 getBabelLoader : getBabelLoaderDeprecated ,
199214 getCacheLoader : getCacheLoaderDeprecated ,
200215 } ;
0 commit comments