react plugins 配置需要注意的

一下只是举个例子,

如果你需要配置两个插件,有类似这样的代码在babelrc:

{
    "plugins": [
        ["import", { "libraryName": "antd", "style": "css" }],
        ["import", { "libraryName": "antd-mobile", "style": "css" }]
    ],
    "presets": [
        "react-app"
    ]
}

会爆出重复的错误,如下:

Error: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.

plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
at Generator.next (<anonymous>)
at new Promise (<anonymous>)

这告诉了我们,需要再加入一个值在对象中,来标识这是不一样的东西

这时候可以这么写:

{
    "plugins": [
        ["import", { "libraryName": "antd", "style": "css" },"pc"],
        ["import", { "libraryName": "antd-mobile", "style": "css" },"mobile"]
    ],
    "presets": [
        "react-app"
    ]
}

问题解决

猜你喜欢

转载自www.cnblogs.com/llcdbk/p/12175957.html