我正在开发一个使用“create-react-app my-app --template cra-template-pwa-typescript”命令创建的反应应用程序。 此外,我正在为界面使用 material-ui 包。 现在我想通过cdn使用material-ui。所以我需要通过“externals”配置排除这个包。我正在使用“react-app-rewired”来覆盖默认配置。
但我没有找到定义外部的正确方法。找了几个例子, 例如:
externals = [
//...other externals working fine
/@material-ui\/.*/
]
或
externals = [
"@material-ui/core",
"@material-ui/icons",
/@material-ui\/core\/.*/,
/@material-ui\/icons\/.*/,
}
但是当使用这种方法时,我在编译时出错
Failed to compile.
Failed to minify the code from this file:
external "@material-ui/core":1
还尝试了此处描述的解决方案: https://github.com/mui-org/material-ui/issues/11777#issuecomment-452306347 在这里我没有收到错误,但是 material-ui 包没有排除并且仍然是捆绑的。