配置在babelv7中合并

问题描述 投票:0回答:1

我刚刚升级到babelv7,之前我有一个具有一些别名的默认环境和一个具有一些别名的测试环境,现在在babel用来合并两个配置的测试环境中,此功能已被删除,如何无需重复两次别名即可实现此合并功能。

这是我的babel.config.js

module.exports = {
  presets: ['custom-preset'],
  env: {
    test: {
      presets: ['@babel/preset-env', '@babel/preset-react'],
      plugins: [
        'transform-class-properties',
        [
          'module-resolver',
          {
            root: ['./app'],
            alias: {
              'test-util': './node_modules/test-util/lib',
            },
          },
        ],
      ],
    },
  },
  ignore: ['node_modules'],
  plugins: [
    [
      'transform-imports',
      {
        lodash: {
          transform: 'lodash/${member}',
          preventFullImport: true,
        },
      },
    ],
    [
      'module-resolver',
      {
        root: ['./app'],
        alias: {
          'module1': './src/components/module1',
        },
      },
    ],
  ],
};

javascript reactjs babeljs babel
1个回答
1
投票
Babel 7中合并的主要变化是事物实际上已经合并了[[more,因此不是此配置生成具有两个不同配置的module-resolver

two个实例,test中的一个将overwrite顶层模块的配置。

要告诉Babel它们是两个独立的插件,您需要至少给它们一个唯一的名称,该名称是作为插件项数组中的第三个条目传递的字符串,例如]] plugins: [ 'transform-class-properties', [ 'module-resolver', { root: ['./app'], alias: { 'test-util': './node_modules/test-util/lib', }, }, 'testing-resolver' // A name for the plugin so it is unique and doesn't overwrite ], ],
© www.soinside.com 2019 - 2024. All rights reserved.