Object | FunctionundefinedWith tools.babel you can modify the options of babel-loader.
Please note the limitations of tools.babel in the following usage scenarios:
tools.babel option will significantly slow down the Rspack's build speed. This is because Rspack defaults to using SWC for compilation, and configuring Babel will cause the code to be compiled twice, resulting in additional compilation overhead.tools.babel option will not take effect.When tools.babel is of type Function, the default Babel configuration will be passed as the first parameter. You can directly modify the configuration object or return an object as the final babel-loader configuration.
The second parameter of the tools.babel function provides some more convenient utility functions. Please continue reading the documentation below.
The above example is just for reference, usually you don't need to manually configure babel-plugin-import, because Modern.js already provides a more general source.transformImport configuration.
When tools.babel's type is Object, the config will be shallow merged with default config by Object.assign.
Note that Object.assign is a shallow copy and will completely overwrite the built-in presets or plugins array, please use it with caution.
When tools.babel is a Function, the tool functions available for the second parameter are as follows:
(plugins: BabelPlugin[]) => voidAdd some Babel plugins. For example:
(presets: BabelPlugin[]) => voidAdd Babel preset configuration. (No need to add presets in most cases)
(plugins: string | string[]) => voidTo remove the Babel plugin, just pass in the name of the plugin to be removed, you can pass in a single string or an array of strings.
(presets: string | string[]) => voidTo remove the Babel preset configuration, pass in the name of the preset to be removed, you can pass in a single string or an array of strings.
(options: PresetEnvOptions) => voidModify the configuration of @babel/preset-env, the configuration you pass in will be shallowly merged with default config. For example:
(options: PresetReactOptions) => voidModify the configuration of @babel/preset-react, the configuration you pass in will be shallowly merged with default config. For example:
Deprecated, please use source.include instead, both have the same functionality.
Deprecated, please use source.exclude instead, both have the same functionality.
After modifying the babel-loader configuration through tools.babel, you can view the final generated configuration in Rsbuild debug mode.
First, enable debug mode by using the DEBUG=builder parameter:
Then open the generated (webpack|rspack).config.web.js file and search for the babel-loader keyword to see the complete babel-loader configuration.