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"
    ]
}

问题解决


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM