-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use Material-UI framework #14
Comments
Thanks for reporting this, @Salmon42. If the suggestion in the other issue to add 'unsafe-inline' doesn't work, I'd suggest modifying your webpack.config.js in this way. Before // loads .css files
{
test: /\.css$/,
include: [path.resolve(__dirname, "app/src")],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader"
}
],
resolve: {
extensions: [".css"]
}
}, After // loads .css files
{
test: /\.css$/,
//include: [path.resolve(__dirname, "app/src")], // removed!
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader"
}
],
resolve: {
extensions: [".css"]
}
}, My thought is that because webpack is only pulling in .css based on the app directory (instead of the It appears that they are doing some kind of process to import the css into each component. I took a little bit to look at it for you but I don't seem to make sense of it. If my suggestion above doesn't work, I recommend asking the material ui team how the css files are imported, so then we can better understand how to change the webpack/csp settings so material ui works in this template. FYI this file might also be helpful to look at, but that's just a guess of mine. |
I suppose the problem could be related to the idea how material-ui processes CSS styles for each component. If I take a look at the DOM through This might be incorrect idea, but I have a feeling that these 4 styles (each containing few css declarations for the given component) are ignored because they are not contained in the "compiled" main.css, which is built from all CSS files inside app/src. I tried to search in material-ui whether it's the only way to use default styles of the components, if there is something I could force it to generate the styles into the main.css, but that is way out of my understanding. Sadly, the only thing I found that "fixes" this issue was by commenting out the whole CSP Webpack Plugin ( About the sources you shared, I took a look into them, but I feel that codes only supports writing style sheets in I'm pretty new to this combination of technologies, so if I said anything that doesn't make any sense, my apologies. |
@Salmon42 have you made any progress on this issue? I want to understand if it is still open or if you solved for it. |
I solved it only partially, by removing the I plan to look at this issue again within few months, when I have more time and knowledge about webpack, babel and some other stuff you are using in this template. Thanks for help for now! |
I figured this out by following your links @reZach. The material-ui doc link was to an old version and once I looked at the latest docs, I saw the answer.
Also need to add uuid for creation of the nonce: create-nonce.js
webpack.development.js
index.ejs (formally index.html)
The same change made to |
@ecolman Looks good to me, thanks for sharing your solution here! |
@ecolman you're the best! One addition, I found that the CspHtmlWebpackPlugin actually generates its own nonce on the script element, which conflicted with the UUID generated nonce. So I removed the UUID one in favour of the plugin-generated nonce. Was there a reason why you made your own? |
@b-zurg I wasn't aware that the the |
Well I can post my plugin call, it's almost nothing, new CspHtmlWebpackPlugin({
"base-uri": ["'self'"],
"object-src": ["'none'"],
"script-src": ["'self'", ...(!isProd ? ["'unsafe-eval'"] : [])], //included for react-hot-loader
"frame-src": ["'none'"],
"worker-src": ["'none'"],
}), I have a boolean called isProd declared elsewhere to ensure that The CSP appears to build a sha-based nonce. Here's my generated html: <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy"
content="base-uri 'self'; object-src 'none'; script-src 'self' 'unsafe-eval' 'nonce-tVZvi9VxJuouaojo+5nChg=='; style-src 'unsafe-inline' 'self' 'unsafe-eval'; frame-src 'none'; worker-src 'none'">
<meta charset="utf-8">
<title>myapp</title>
</head>
<body>
<div id="app"></div>
<script src="/window/index.js" nonce="tVZvi9VxJuouaojo+5nChg=="></script>
</body>
</html> |
I tried to add React Material-UI to the project template.
This is how it looks in
package.json
(by simply following the installation routine on material-ui page):And in one of the components simply used material button:
Somehow, I seem to hit unsolvable error similar to this issue.
I tried to modify this in
webpack.development.js
:but it had no effect.
Is there a way to get Material-UI working along with this template? I feel like I'm terribly missing something trivial, but I don't know what else to try. Thanks in advance.
The text was updated successfully, but these errors were encountered: