我在webpack.config中为material-ui
定义了外部module.exports = [{
entry: ...
output:...
externals: {
react: {
commonjs: "react",
commonjs2: "react"
},
"material-ui": {
commonjs: "material-ui",
commonjs2: "material-ui"
}
},
module: ...
}];
仍然给出错误,如 -
无法解析模块'material-ui / IconButton'......
在我的条目js文件中,我有
import React, {Component} from "react";
import IconButton from "material-ui/IconButton";
.....
.....
答案 0 :(得分:3)
好的,我解决了。外部期望完整的路径。
所以,
import {IconButton} from "material-ui"
或
externals: {
"material-ui/IconButton": {
commonjs: "material-ui/IconButton",
...
}
}
会奏效。当然,第二种选择在这里是不合理的