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