一下只是舉個例子,
如果你需要配置兩個插件,有類似這樣的代碼在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" ] }
問題解決