Used to import the code and style of the component library on demand, which is equivalent to babel-plugin-import.
The difference between it and babel-plugin-import is that source.transformImport is not coupled with Babel. Builder will automatically identify whether the currently used tools is Babel, SWC or Rspack, and apply the corresponding on-demand import configuration.
When the Ant Design component library <= 4.x version is installed in the project, Builder will automatically add the following default configurations:
When the Arco Design component library is installed in the project, Builder will automatically add the following default configurations:
When you add configurations for antd or @arco-design/web-react, the priority will be higher than the default configurations mentioned above.
When using the above antd default configuration:
The source code is as follows:
It will be transformed into:
You can manually set transformImport: false to disable the default config.
For example, if you use externals to avoid bundling antd, because transformImport will convert the imported path of antd by default, the matching path changes and externals cannot take effect. At this time, you can disable transformImport to avoid this problem.
stringThe original import path that needs to be transformed.
string'lib'Used to splice the transformed path, the splicing rule is ${libraryName}/${libraryDirectory}/${member}, where member is the imported member.
Example:
Out:
booleanundefinedDetermines whether to import related styles. If it is true, the path ${libraryName}/${libraryDirectory}/${member}/style will be imported. If it is false or undefined, the style will not be imported.
When it is set to true:
Out:
stringundefinedThis configuration is used to splice the import path when importing styles. If this configuration is specified, the style configuration option will be ignored. The spliced import path is ${libraryName}/${styleLibraryDirectory}/${member}.
When it is set to styles:
Out:
booleantrueWhether to convert camelCase imports to kebab-case.
Example:
Out:
booleantrueWhether to convert import statements to default imports.
Example:
Out:
((member: string) => string | undefined) | stringundefinedCustomize the imported path after conversion. The input is the imported member. For example, configure it as (member) => `my-lib/${member}` , which will convert import { foo } from 'bar' to import foo from 'my-lib/foo'.
When using Rspack to build, function configurations cannot be used, but you can use handlebars template strings. For the above function configuration, you can use the following template instead of my-lib/{{ member }}, or use some built-in helper methods, such as my-lib/{{ kebabCase member }} to convert it to kebab-case format. In addition to kebabCase, there are also camelCase, snakeCase, upperCase, and lowerCase that can be used.
((member: string) => string | undefined) | stringundefinedCustomize the imported style path after conversion. The input is the imported member. For example, configure it as (member) => `my-lib/${member}` , which will convert import { foo } from 'bar' to import foo from 'my-lib/foo'.
When using Rspack to build, function configurations cannot be used, but you can use handlebars template strings. For the above function configuration, you can use the following template instead of my-lib/{{ member }}, or use some built-in helper methods, such as my-lib/{{ kebabCase member }} to convert it to kebab-case format. In addition to kebabCase, there are also camelCase, snakeCase, upperCase, and lowerCase that can be used.