I have defined externals in webpack.config for material-ui
module.exports = [{
entry: ...
output:...
externals: {
react: {
commonjs: "react",
commonjs2: "react"
},
"material-ui": {
commonjs: "material-ui",
commonjs2: "material-ui"
}
},
module: ...
}];
Still its giving error like-
Cannot resolve module 'material-ui/IconButton'......
In my entry js file, I have
import React, {Component} from "react";
import IconButton from "material-ui/IconButton";
.....
.....
The Webpack Externals are used to ignore the packages from the application while bundling and adding them as external CDN script references.
Webpack externals tell Webpack to exclude a certain import from the bundle. Often externals are used to exclude imports that will be loaded via CDN. For example, suppose you are implementing server-side rendering with Vue and Express, but your client-side code imports Vue via a CDN.
webpack does not include node_modules dependency!!
Ok I solved it. External expects complete path.
So either,
import {IconButton} from "material-ui"
or
externals: {
"material-ui/IconButton": {
commonjs: "material-ui/IconButton",
...
}
}
will work. Ofcourse, second option is not reasonable here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With