webpack.config中定义的外部仍然未找到错误模块

时间:2017-01-24 08:26:46

标签: webpack webpack-externals

我在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";
.....
.....

1 个答案:

答案 0 :(得分:3)

好的,我解决了。外部期望完整的路径。

所以,

import {IconButton} from "material-ui"

externals: {
  "material-ui/IconButton": {
    commonjs: "material-ui/IconButton",
    ...
  }
}

会奏效。当然,第二种选择在这里是不合理的