@@ -10,6 +10,8 @@ import {
1010import * as hermesParser from 'hermes-parser' ;
1111
1212import type { LoaderContext } from '@rspack/core' ;
13+ import { type BabelLoaderOptions , getOptions } from './options.js' ;
14+ import { repackBabelPreset } from './preset.js' ;
1315
1416export const raw = false ;
1517
@@ -71,7 +73,6 @@ const getBabelRC = (() => {
7173 }
7274
7375 // If we found a babel config file, extend our config off of it
74- // otherwise the default config will be used
7576 if ( fs . existsSync ( projectBabelRCPath ) ) {
7677 babelRC . extends = projectBabelRCPath ;
7778 }
@@ -92,8 +93,11 @@ function buildBabelConfig(
9293 code : true ,
9394 cwd : options . projectRoot ,
9495 filename,
95- highlightCode : false ,
96+ highlightCode : true ,
9697 compact : false ,
98+ comments : true ,
99+ minified : false ,
100+ presets : [ repackBabelPreset ] ,
97101 } ;
98102
99103 return { ...babelRC , ...extraConfig } ;
@@ -108,9 +112,10 @@ const transform = ({
108112 options : CustomOptions ;
109113 src : string ;
110114} ) => {
115+ const builtConfig = buildBabelConfig ( filename , options ) ;
111116 const babelConfig : TransformOptions = {
112117 sourceType : 'unambiguous' ,
113- ...buildBabelConfig ( filename , options ) ,
118+ ...builtConfig ,
114119 caller : { name : 'repack' } ,
115120 ast : false ,
116121 cloneInputAst : false ,
@@ -129,9 +134,13 @@ const transform = ({
129134 return transformFromAstSync ( sourceAst , src , babelConfig ) ;
130135} ;
131136
132- export default function babelLoader ( this : LoaderContext , source : string ) {
137+ export default function babelLoader (
138+ this : LoaderContext < BabelLoaderOptions > ,
139+ source : string
140+ ) {
133141 this . cacheable ( ) ;
134142 const callback = this . async ( ) ;
143+ const options = getOptions ( this ) ;
135144
136145 try {
137146 const result = transform ( {
@@ -140,7 +149,8 @@ export default function babelLoader(this: LoaderContext, source: string) {
140149 options : {
141150 enableBabelRCLookup : true ,
142151 // this is currently broken in Rspack and needs to be fixed upstream
143- projectRoot : this . rootContext ,
152+ // for now we can pass this as an option to loader
153+ projectRoot : options . projectRoot ,
144154 } ,
145155 } ) ;
146156 // @ts -ignore
0 commit comments