tools.babel
适用的工程方案
MWA,模块。
- 类型:
Object | Function
- 默认值:
{ presets: ['@modern-js/babel-preset-app'], plugins: [] }
通过 tools.babel
可以修改 babel-loader 的配置项。
类型
值为 Object
类型时,与默认配置通过 Object.assign
合并。
modern.config.js
export default defineConfig({
tools: {
babel: {
plugins: [
[
'babel-plugin-import',
{
libraryName: 'xxx-components',
libraryDirectory: 'es',
style: true,
},
],
],
},
},
});
值为 Function
类型时,默认配置作为第一个参数传入,可以直接修改配置对象,也可以返回一个值作为最终结果:
modern.config.js
export default defineConfig({
tools: {
babel: config => {
config.plugins.push([
'babel-plugin-import',
{
libraryName: 'xxx-components',
libraryDirectory: 'es',
style: true,
},
]);
},
},
});
插件信息
目前内部集成的 babel 预设如下所示:
目前内部集成的 babel 插件如下所示:
- @babel/plugin-proposal-decorators
- @babel/plugin-proposal-object-rest-spread
- @babel/plugin-transform-runtime
- @babel/plugin-syntax-dynamic-import
- @babel/plugin-proposal-function-bind
- @babel/plugin-proposal-export-default-from
- @babel/plugin-proposal-export-namespace-from
- @babel/plugin-proposal-pipeline-operator
- @babel/plugin-proposal-partial-application
- @babel/plugin-syntax-dynamic-import
- babel-plugin-transform-react-remove-prop-types
- babel-plugin-styled-components
- babel-plugin-macros
- babel-plugin-dynamic-import-node
- babel-plugin-import
- babel-plugin-lodash